Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Correct managed code from C++
    primarykey
    data
    text
    <p>I have to use this external functions "GetOpenedFiles" (more info to: <a href="http://www.codeproject.com/KB/shell/OpenedFileFinder.aspx" rel="nofollow">http://www.codeproject.com/KB/shell/OpenedFileFinder.aspx</a>) into my C# application. I don't know as I can write a wrapper of this function:</p> <pre><code>void GetOpenedFiles(LPCWSTR lpPath, OF_TYPE Filter, OF_CALLBACK CallBackProc, UINT_PTR pUserContext); </code></pre> <p><em><strong></em> ORIGINAL C++ CODE (OpenFilefinder.h)</strong></p> <pre><code>enum OF_TYPE { FILES_ONLY = 1, MODULES_ONLY = 2, ALL_TYPES = 3 }; struct OF_INFO_t { DWORD dwPID; LPCWSTR lpFile; HANDLE hFile; }; typedef void (CALLBACK* OF_CALLBACK)(OF_INFO_t OpenedFileInf0, UINT_PTR uUserContext ); extern "C" __declspec(dllexport) void ShowOpenedFiles( LPCWSTR lpPath ); extern "C" __declspec(dllexport) void GetOpenedFiles( LPCWSTR lpPath, OF_TYPE Filter, OF_CALLBACK CallBackProc, UINT_PTR pUserContext ); </code></pre> <p><strong>MY C# APPLICATION:</strong> </p> <pre><code> public enum OF_TYPE : int { FILES_ONLY = 1, MODULES_ONLY = 2, ALL_TYPES = 3 } public struct OF_INFO_t { ?????? dwPID; ?????? lpFile; ?????? hFile; } [DllImport("OpenFileFinder.dll", EntryPoint = "GetOpenedFiles")] static extern void GetOpenedFiles(??????? lpPath, OF_TYPE filter, ????? CallBackProc, ????? pUserContext); </code></pre> <p>How can I use this dll function correctly in my C# app?</p> <p>EDIT:</p> <p>This is my latest snippet, but never invoke callback function:</p> <pre><code>namespace Open64 { class Program { public Program() { GetOpenedFiles("C:\\", OF_TYPE.ALL_TYPES, CallbackFunction, UIntPtr.Zero); } //void GetOpenedFiles(LPCWSTR lpPath, OF_TYPE Filter, OF_CALLBACK CallBackProc, UINT_PTR pUserContext); public enum OF_TYPE : int { FILES_ONLY = 1, MODULES_ONLY = 2, ALL_TYPES = 3 } public struct OF_INFO_t { Int32 dwPID; String lpFile; IntPtr hFile; } public delegate void CallbackFunctionDef(OF_INFO_t info, IntPtr context); [DllImport("OpenFileFinder.dll", EntryPoint = "GetOpenedFiles")] static extern void GetOpenedFiles(string lpPath, OF_TYPE filter, CallbackFunctionDef CallBackProc, UIntPtr pUserContext); public void CallbackFunction(OF_INFO_t info, IntPtr context) { Console.WriteLine("asd"); } [STAThread] static void Main() { new Program(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload