Hi everyone and thank you for your time. This was created in Visual Studio 2012,and I'm using the standard Windows Libraries.
I am attempting to call a DLL function explicitly and I believe the code I've written is correct; however, I am receiving an error. I'm not sure if it's an error in something that I've written in the small C console application or from the DLL which I do not have access to the internal workings of.
//global area HINSTANCE _createInstance; typedef UINT (CALLBACK* LPFNDLLFUNCLOOKUP)(AccuInput*, AccuOut*); LPFNDLLFUNCLOOKUP lpfnDllFuncCASSLookup; typedef UINT (CALLBACK* LPFNDLLFUNCINIT)(BSTR); LPFNDLLFUNCINIT lpfnDllFuncInit; typedef UINT (CALLBACK* LPFNDLLFUNCCLOSE)(); LPFNDLLFUNCCLOSE lpfnDllFuncClose; HMODULE unmanagedLib; Here is my main function:
int main() { // Load Library BSTR configFile; unmanagedLib = LoadLibraryA((LPCSTR) "AccuAddressUnMgd.dll"); // Initialize AccuAddress COM dll lpfnDllFuncInit = (LPFNDLLFUNCINIT)GetProcAddress(unmanagedLib, (LPCSTR)"Init"); // This function will lookup the address lpfnDllFuncCASSLookup = (LPFNDLLFUNCLOOKUP)GetProcAddress(unmanagedLib, (LPCSTR)"AccuCassLookup"); // This function will call AccuAddress COM DLL Close function lpfnDllFuncClose = (LPFNDLLFUNCCLOSE)GetProcAddress(unmanagedLib, (LPCSTR)"Close"); // Append “config.acu” file path. configFile = SysAllocString(L"C:\PathTo\Config.acu"); printf("ConfigPath created"); lpfnDllFuncInit(configFile); printf("ConfigFile consumed"); SysFreeString(configFile); return 0; } This is the error that I receive:
Unhandled exception at at 0x75D4C54F in RDISample1.exe: Microsoft C++ exception: _com_error at memory location 0x001AFAC0. The error occurs at:
lpfnDllFuncInit(configFile); So, I guess my question is two parts. Based off the code can I say for a fact that the error is in the DLL function?
Second question, when calling GetProcAddress what would be the point (if any) for encapsulating the string in LPCSTR like a function versus typecasting? ie
lpfnDllFuncClose = (LPFNDLLFUNCCLOSE)GetProcAddress(unmanagedLib, LPCSTR("Close")); Thanks again for the help. I've been doing a fair amount of research yet DLLs still have been puzzled.
\\in your paths instead of\. May not be contributing to the error, but it probably isn't helping any.SysFreeStringline and see if it works)