On 8/5/2010 10:55 AM, Rob Richardson wrote:
> Greetings!
>
> I have an ActiveX DLL written in MS Visual C++ 6, and accessed by an
> application written in C#. When the AxDLL is first accessed, it tries
> to find out what its path is using the following code:
>
> hModule = GetModuleHandle(_T("AnnealHeatModel.dll"));
> ::GetModuleFileName(hModule, szFilePath, _MAX_PATH);
> TmpString = szFilePath;
>
> The working directory for the ActiveX DLL is supposed to be the folder
> that contains the DLL.
>
> But when I added a statement to write szFilePath to a file, I saw that
> it is the path to the executable file (the C# application), not the DLL.
> Apparently, the call to GetModuleHandle() fails, hModule is set to NULL,
> and passing NULL in to GetModuleFileName() returns the executable's file
> name. I am guessing that the call to GetModuleHandle() fails because
> the DLL is not loaded using LoadLibrary(), since it's being called from
> a C# application.
>
> So what is the correct way to get my DLL's path? I really don't want to
> hard-code it.
>
> Thanks very much!
>
> RobR
What does GetLastError() return after calling GetModuleHandle() and it
returns NULL?
Also, what does Process Explorer say about the DLLs that are loaded?
Make sure the DLL is being loaded with that name. The search is
case-insensitive, but if it gets copied to another directory and renamed
before loading, that makes it a lot harder to figure out.
Use assertions or do significant error checking when calling APIs.
--
Thomas Hruska
CubicleSoft President
Barebones CMS is a high-performance, open source content management
system for web developers operating in a team environment.
An open source CubicleSoft initiative.
Your choice of a MIT or LGPL license.
http://barebonescms.com/