   Loading DLL's in C++
  HiI need some help in loading a DLL into C++ and accessing its methods. I can not give as detailed description of the DLL as its a propriety piece of junk and the company that made it have horrible tech support (Which is why I'm asking here :)) As part of this I have replaced some of the actual function/DLL names for made up ones. Sorry.The DLL is described as an OLE object (DLL_NAME.OLE_OBJECT) and I can load it in C# buy adding it as a reference and then doing (private DLL_NAME.OLE_OBJECT objDLL_NAME;objDLL_NAME = new DLL_NAME.OLE_OBJECT();objDLL_NAME.Initialize(intSysType, strIp, strParam2, strParam2, null, out intCustNo, out strProduct, out strProductVer, out strGUID, out strErrDes, out intOutcome);This works fine, but when I come to load the DLL in C++ (VS8) and access its methods I come across a whole heap of trouble. (Ignore the fact that there is no error handling etc)typedef int (*Initialize__PROC)(int, LPTSTR, LPTSTR, LPTSTR, LPTSTR, int *, LPTSTR *, LPTSTR *, LPTSTR *, LPTSTR *, int *);HINSTANCE hDLL_NAME = LoadLibrary(TEXT("DLL_NAME.dll"));FARPROC fp = GetProcAddress(hDLL_NAME, "Initialize");Initialize__PROC ptr = (Initialize__PROC) fp;LPTSTR productName, version, loginID, error;int CDB, outcome;ptr(0, TEXT("127.0.0.1"), TEXT("dob"), TEXT("typ"), NULL, &CDB, &productName, &version, &loginID, &error, &outcome);The GetProcAddress() method is unable to find the Initialize() method, so I used Dependency Walker to have a look at what was in the DLL and all I can see are the 4 DLLRegisterServer type functions.Anyone got any ideas why I can access the methods in C# but not in C++? This is driving me crazy.Thanks.P.S. I have not used C++ for a few years so I may be rusty and/or missing the obvious.   
  Forgot to mention that the C++ code is done in a Win32 console project.   ;  I hanen't much experience with C# and and Dlls, but I imagine that "Initialize" is a method that belongs to the class "DLL_NAME.OLE_OBJECT". Not necesseraly an exported function of the actual dll. The dll probably creates COM object that have an Initialize() method in their interface. You should use whatever support C++ or Win32 has for OLE.   ;  Do you have any totorial links to C++ OLE?Thanks.   ;  My guess is that C# is better at figuring out the exact entry point name than C++ and that your entry point name is mangled. Check out the following command:  dumpbin /exports "yourdll".dllYou could also download Dependency Walker (http://www.dependencywalker.com/) which is basically "dumpbin" with a fancy UI on top of it. Both will show you the _exact_ function entry point's name.If it happens that you are the one that created the DLL in the first place and it has been written in C++, then check out the following C++ language construct:extern "C"   ;Quote:Original post by Anonymous PosterMy guess is that C# is better at figuring out the exact entry point name than C++ and that your entry point name is mangled. Check out the following command:  dumpbin /exports "yourdll".dllYou could also download Dependency Walker (http://www.dependencywalker.com/) which is basically "dumpbin" with a fancy UI on top of it. Both will show you the _exact_ function entry point's name.If it happens that you are the one that created the DLL in the first place and it has been written in C++, then check out the following C++ language construct:extern "C"He already said that he used Depedency Walker and found no such function, that's why I said that Initialize() probably isn't an exported function at all, but a function that is contained in the virtual function table of the object that is returned by the dll. If I'm not mistaken(haven't used it in a while), that's how COM works.   ;  GetProcAddress doesn't work well with mangled names either.   ;  Use the Ole Viewer from the visual studio tools, use the file->view typelib option to open the DLL and look inside it for COM objects...Alternatively use #import "dllname.dll" in one of your files to generate C++ wrappers for the objects inside the DLL...Jans.   ;Quote:Original post by JansicUse the Ole Viewer from the visual studio tools, use the file->view typelib option to open the DLL and look inside it for COM objects...Alternatively use #import "dllname.dll" in one of your files to generate C++ wrappers for the objects inside the DLL...Jans.I'm using the OLE Viewer in VS 7.1 as I can not find it in VS 8. Inside the file I have the following informationlibrary DLL_NAME{    // TLib :// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}    importlib("stdole2.tlb");    // Forward declare all types defined in this typelib    interface IOLE_OBJECT;    //Notice the letter I here    [ odl, uuid(439DCA81-AEDA-4BDB-90D4-5FE9ECFE690B), version(1.0), helpstring("Dispatch interface for OLE_OBJECT Object"), dual, oleautomation    ]    interface IOLE_OBJECT: IDispatch {   [id(0x00000016)]   HRESULT InitializeWithID(    [in] int applicationType,[in] BSTR address,[in] BSTR param1,[in] BSTR param2,[in] BSTR databaseName,[out] VARIANT* sessionID,[out] VARIANT* vProductName,[out] VARIANT* vVersion,[out] VARIANT* vLoginID,[out] VARIANT* vError,[out] VARIANT* vOutcome,[out, retval] VARIANT* vResult);    };    [ uuid(368003BD-C400-4603-9788-0A8FA0230FB5), version(1.0), helpstring("OLE_OBJECT Object")    ]    coclass OLE_OBJECT {   [default] interface IOLE_OBJECT;    };How do I use this information to access the object?Thanks.@Anonymous Poster - I'm glad to say that I did not have anything to do with the making of the crappy DLL.;  I have just tried #import "dllname.dll"and I then have in the main functionDLL_NAME::OLE_OBJECT bob = new DLL_NAME::OLE_OBJECT();I must admit that I don't know what the significance of the :: are as I have never had course to use them before.Anyway this on compile produces the following error message:Error1error C2079: 'bob' uses undefined struct 'DLL_NAME::OLE_OBJECT'Anyone got any ideas about this. Were getting closer. Thanks again.   