-1

I’ve got a c++ dll written in visual studio 2012. I’d like to load it in a C# program(VS2012 too) with using of LoadLibrary function.
I set the SetLastError = true to get the probabilistic returned error code by LoadLibrary. When I run my C# program I always receive 998 error code but I can’t understand what’s wrong with it!
Should you help me to resolve this problem,please?
Any help would be appreciated.

(It should be mentioned that I saw some posts about error code 998 but none of them couldn't give me a solution.)

s.a.t
  • 39
  • 8
  • 2
    Might be beneficial noting the posts in case you missed something someone else might pick up on. – Phil Cooper Jan 05 '16 at 09:09
  • It is nasty, the DllMain() entrypoint of the DLL failed with an AccessViolationException. About the worst possible thing that can go wrong. This is not something you can fix yourself, or ask SO users to fix for you, you must use a telephone to get help from the author or owner. – Hans Passant Jan 05 '16 at 12:13
  • @HansPassant Due to sayings of DLL's developer , she used : `extern "C" { __declspec(dllexport) int __stdcall Start(int ID) { //body } }` to export the `Start(int ID)` method and DllMain has not been used. – s.a.t Jan 05 '16 at 19:28
  • I’m so sorry @PhilCooper but my English is weak and I can’t understand what do you mean! Is it possible to tell me much easier what exactly do you mean?! – s.a.t Jan 10 '16 at 19:22
  • @HansPassant If my post is banal I would like to apologize and I would be grateful if you would help me to resolve this problem. – s.a.t Jan 10 '16 at 20:27
  • @s.a.t do you have the urls for 'I saw some posts about error code 998'? – Phil Cooper Jan 11 '16 at 10:30
  • @PhilCooper could you please tell me how can I do this instruction:″To troubleshoot the LoadLibrary() failure, run the application under a debugger and enable first chance exception handling for the C0000005 Access Violation exception. If an access violation occurs when the LoadLibrary() function is called, the application will break into the debugger. The debugger's call stack can then be used to trace where the exception occurred. The stack trace should help you narrow down the actual problem related to the exception being encountered.″ – s.a.t Jan 11 '16 at 21:22

1 Answers1

0

In response to this comment "please tell me how can I do this instruction":

To troubleshoot the LoadLibrary() failure, run the application under a debugger and enable first chance exception handling for the C0000005 Access Violation exception. If an access violation occurs when the LoadLibrary() function is called, the application will break into the debugger. The debugger's call stack can then be used to trace where the exception occurred. The stack trace should help you narrow down the actual problem related to the exception being encountered.

  1. Open your project in Visual Studio

  2. In the menu, click Debug > Exceptions

  3. In the Exceptions window, click Find... and enter C0000005 click Ok

  4. Check the box next to the highlighted exception under the column Thrown.

Now, when you debug your program and the exception is thrown, it will break and you should be able to at least inspect the exception details of the thrown exception.

It's likely you'll be thrown into disassembly window so you may not see any readable code. If the exception detail isn't enough, you could try decompiling with Dot Peek.

Here's a tutorial on enabling Dot Peek as a symbol server. Doing this will hopefully decompile the library on-the-fly so you can start inspecting the line of code that has caused the exception.

Phil Cooper
  • 3,083
  • 39
  • 63