1

I'm writing a WPF app that uses PINVOKE to make calls to a dll that I'm also writing. In one of the exported functions in the dll, the SetupDiGetClassDevs is called. At this point, when running the app on XP, I get an error, first of all a dialog box saying:

"The procedure entry point RegOpenKeyExW could not be located in the dynamic link library KERNAL32.dll."

Clicking ok then leads me to an unhandled exception dialog. Both the WPP app and the dll are built with VS2010 on a Win7 machine, and the app runs fine on Win7 systems. The problem only happens when running the app on XP. If I avoid the SetupDiGetClassDevs (and subsequent SetUpdi function calls) in the dll, then nothing goes wrong; so it seems the PINVOKE mechanism is working ok.

Any ideas what is going wrong? I'm a bit confused about seeing RegOpenKeyExW referenced, as the dll is not built with UNICODE enabled.

Thanks Tom

Tom Davies
  • 2,386
  • 3
  • 27
  • 44

1 Answers1

1

I strongly suspect that the problem lies in some P/invoke code of yours, or perhaps a direct LoadLibrary/GetProcAddress bind in your DLL. The thing is, RegOpenKeyEx is not part of kernel32. It is exported by advapi32. I can't believe that you have a .lib file that is tries to import it from kernel32 so I think you should look for a P/invoke or a GetProcAddress in your code or perhaps third party code that you are including.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I've stripped things right back - my app only makes one p/invoke call, and the dll function it calls does nothing other than call SetupDiGetClassDevs. If I remove the call to SetupDiGetClassDevs in the dll, I get no error. The dll statically links to Setupapi.lib. Like you say, it's bizarre that KERNEL32 is mentioned. There are no LoadLibrary/GetProcAddress references. – Tom Davies Oct 14 '11 at 16:19
  • Where did you get Setupapi.lib from? – David Heffernan Oct 14 '11 at 16:22
  • I've just got Setupapi.lib listed in the 'Addiontal Dependencies' field on the Linker/Input section of the dll project settings. The dll won't build without it there. – Tom Davies Oct 14 '11 at 16:36