Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I am using the following code to load dlls
[DllImport("kernel32.dll",EntryPoint= "LoadLibraryA")]
public static extern IntPtr LoadLibrary(string dllToLoad);


This works fine in Vista and Windows 7 (also in 64bit environment)
But does not works in XP 64-Bit Version

I have seen the last error,it's giving 126 which means "module not found".
Can anyone give some clue to resolve this problem???
Posted
Comments
Indivara 21-Jan-11 9:58am    
1. Does kernel32.dll exist on XP x64? (I think it should, just checking)
2. Does it have to be LoadLibraryA? Try without the 'A'?

I found this here on social.msdn.microsoft.com from moderator "Ray M":

"Any CPU will give you a 64 bit process on win64, you cannot load a 32bits dll into a 64 bits process. If you have no 64 bits versions of your dlls you can change your soltion platform from 'any cpu' to 'x86' to force a 32 bits process which has no issues loading 32 bits dlls."

I'd go with that advice and set platform to "x86". Why it works on Vista and Weven is beyond me, but I think could be that the have some kind of detection built into them that takes care of forcing the 32 bit process. You can check of course if the windows XP 64 bit system has the kernel32.dll in the appropriate place.

I know I'm poking at your problem with a long and not very solid stick (figuratively speaking), but maybe it helps you to get some ideas. :)

Best Regards,
Manfred
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Jan-11 16:48pm    
Your recommendation will surely work, my 5.
However, must be a way to do PInvoke native 64 to assembly targeted as 64-bit, without WOW64, don't you think so?
Please reply if you can educate me a bit - I haven't work on 64-bit platform for a while now and have no installed 64 platform at the moment.
Yup, I worked out the problem.
I had one dependent .dll which was built in x86 platform.
I replaced it with x64 version it worked.

I found this problem using the "Dependency Walker" tool.
 
Share this answer
 
Resolution by Manfred will certainly work, but... (see my comment).

I think, this is a good starting point:

http://msdn.microsoft.com/en-us/library/ms973190.aspx[^].

Thank you.
--SA
 
Share this answer
 
Comments
Debojyoti Majumder 22-Jan-11 1:44am    
Many thanks for giving the msdn link.
It will be very useful for me.
Make your application to work with any cpu..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900