G
Guest
HOWTO Implement LoadLibrary\GetProcAdrress\FreeLibrary in C#
Please help,
I want to fully implement LoadLibrary\GetProcAdrress\FreeLibrary in C#, and
be able to call functions that I use GetProcAddress on to pass info to
non-.NET apps. I can not use the standard "interop" process, as the DLL's are
created dynamically. I need this:
========================================
[DllImport("kernel32.dll")]
static extern ???HMODULE?? LoadLibrary
(
???LPCTSTR lpFileName???
);
[DllImport("kernel32.dll")]
static extern ???FARPROC?? GetProcAddress
(
???HMODULE hModule,???
???LPCSTR lpProcName???
);
[DllImport("kernel32.dll")]
static extern ???BOOL?? FreeLibrary
(
???HMODULE hModule???
);
// For clarification I CAN NOT USE the following:
//
// [DllImport("My.dll")]
// static extern ???BOOL?? MyFunc
// (
// ???LPCSTR pszParam1???, ???LPCSTR pszParam1???
// );
//
// I can not use this,
main()
{
// Code to create "My.dll"...
// ...
// ...
// ...
// My code actually creates the DLL called "My.dll" at run time. It does
not exist until
// AFTER the fictitious code above runs.
// Now load My.dll, get the MyFunc and run it.
???VAR??? ???VAR???_MyDll = LoadLibrary("My.dll");
???FUNCTION_PROTOTYPE??? ???FUNCTION_PROTOTYPE???_MyFunc;
???FUNCTION_PROTOTYPE???_MyFunc = (???) GetProcAddress(???VAR???_MyDll,
"MyFunc");
// Call My Func...
bool bRet = ???FUNCTION_PROTOTYPE???_MyFunc("Param_Number_1",
"Param_Number_2");
FreeLibrary(???FUNCTION_PROTOTYPE???_MyFunc);
}
Please help,
I want to fully implement LoadLibrary\GetProcAdrress\FreeLibrary in C#, and
be able to call functions that I use GetProcAddress on to pass info to
non-.NET apps. I can not use the standard "interop" process, as the DLL's are
created dynamically. I need this:
========================================
[DllImport("kernel32.dll")]
static extern ???HMODULE?? LoadLibrary
(
???LPCTSTR lpFileName???
);
[DllImport("kernel32.dll")]
static extern ???FARPROC?? GetProcAddress
(
???HMODULE hModule,???
???LPCSTR lpProcName???
);
[DllImport("kernel32.dll")]
static extern ???BOOL?? FreeLibrary
(
???HMODULE hModule???
);
// For clarification I CAN NOT USE the following:
//
// [DllImport("My.dll")]
// static extern ???BOOL?? MyFunc
// (
// ???LPCSTR pszParam1???, ???LPCSTR pszParam1???
// );
//
// I can not use this,
main()
{
// Code to create "My.dll"...
// ...
// ...
// ...
// My code actually creates the DLL called "My.dll" at run time. It does
not exist until
// AFTER the fictitious code above runs.
// Now load My.dll, get the MyFunc and run it.
???VAR??? ???VAR???_MyDll = LoadLibrary("My.dll");
???FUNCTION_PROTOTYPE??? ???FUNCTION_PROTOTYPE???_MyFunc;
???FUNCTION_PROTOTYPE???_MyFunc = (???) GetProcAddress(???VAR???_MyDll,
"MyFunc");
// Call My Func...
bool bRet = ???FUNCTION_PROTOTYPE???_MyFunc("Param_Number_1",
"Param_Number_2");
FreeLibrary(???FUNCTION_PROTOTYPE???_MyFunc);
}