9

HINSTANCE hinstLib=LoadLibrary("C:\\mydll.dll");

I have no idea why I always get 0 in return after running that line of code.

Actually I have also another COM dll namely mydllCOM.dll that I already registered successfully with regsvr32 command. I would like to use the above (mydll.dll) in my application but always fail at the line as mentioned.

The error code I got from GetLastError is 193 and I have no idea, why it is about the wrong type of dll

Balu
  • 2,247
  • 1
  • 18
  • 23
user3462253
  • 146
  • 1
  • 1
  • 5

3 Answers3

14

The error code looks like it has the "wrong bitness", meaning you're probably mixing 32-bit and 64-bit executables/DLLs. The setting in the Project properties "Linker->Advanced->Target Machine" should be set to the same value in your DLL and in the executable loading that DLL.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
okaerin
  • 789
  • 5
  • 23
4

I had a similar problem but with a dll that wasn't mine. The solution was to change the Character set(i.e. Project properties->configuration Properties->general->Character set). The default was unicode and when I changed it to multi-Byte i managed to load the dll.

TBD
  • 509
  • 7
  • 15
1

You can't load 32bit DLLs into 64bit applications and vice versa.

You need to recompile your Application and Dll with the same Linker->Advanced->Target Machine setting.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Abhineet
  • 5,320
  • 1
  • 25
  • 43
  • as Frederic stated it is only for managed languages/code. as for visual studio it targets by default x86 code – okaerin Mar 27 '14 at 10:07