DllImport and Windows 2000

  • Thread starter Thread starter Trecius
  • Start date Start date
T

Trecius

Hello, Newsgroupians:

I have created an unmanaged DLL using Visual Studio 2005, which was created
in Visual C++. I have some functions in the DLL that I am trying to call.
When I "dumpbin -exports ManipLib.dll" I can see all of my exported
functions, which I have defined in my definition file. They are not name
mangled or decorated.

Now, when I call the function in my C# program, I have the following
definition...

[System.Runtime.InteropServices.DllImport(@".\ManipLib.dll", CharSet =
System.Runtime.InteropServices.CharSet.Unicode)]
public static extern IntPtr UserFindWindowW(string lpszWndClass);

All UserFindWindowW does is call FindWindowEx(). Now, I know I can import
the user32.dll instead of this, but I have some other methods later that wrap
functionality of what I am going to do to the window, so this is just my base
case, and it doesn't work in Windows 2000.

When I run the program in WindowsXP, the function succeeds and returns an
IntPtr, or handle, to the window I'm looking for. However, when I run the
program in Windows2000, I am constantly receiving a
System.DllNotFoundException: "Unable to load DLL '.\ManipLib.dll': The
specified procedure could not be found. (Exception from HRESULT: 0x8007007F)."

Now, I know the working directory contains the DLL that I have created, for
just prior to making my extern-call, I do a
MessageBox.Show(System.IO.Directory.GetCurrentDirectory()); This shows my
current working directory correctly, which the directory also contains my
ManipLib.dll. As soon as I hit "OK," the exception is thrown as it tries to
call my DLL method.

What would make this program work for all versions of XP that I have tried,
but continually fail for every Windows 2000 version? I've tried 4 computers
with Windows 2000, each has SP4. Thank you for your help.


Trecius
 
Not sure what's the issue here. Seems that there is difference in the
way the files are searched.

Try to use this (Remove ".\" before the dll's name)

[System.Runtime.InteropServices.DllImport(@"ManipLib.dll", CharSet =
System.Runtime.InteropServices.CharSet.Unicode)]

-
Ashutosh
 
Back
Top