2

I have a DLL which is develeoped in VB.Net. I am trying to call its functions from my vc++ code. The dll has successfully loaded using LoadLibrary function. But when I try calling any function within the dll, it gives a null pointer exception.

I used the dumpbin command to confirm the function arguments within my dll. But it is not listing any functions. Could it be a problem with the dll or does dumpbin support few dlls only? Please help!

C:\Program Files (x86)\Microsoft Visual Studio 11.0>dumpbin ECR.dll Microsoft (R) COFF/PE Dumper Version 11.00.51106.1 Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file ECR.dll

File Type: DLL

Summary

    2000 .reloc
    4000 .rsrc
    2000 .sdata
   16000 .text
RmP
  • 21
  • 7
  • Try `dumpbin /exports ECR.dll` and see if you have the functions listed there. – CristiFati Aug 11 '15 at 11:35
  • i tried *dumpbin /exports ECR.dll* and get the same result. no functions listed. – RmP Aug 11 '15 at 11:38
  • Are any functions *exported* from that DLL? – Vlad Feinstein Aug 11 '15 at 11:43
  • I cannot see the dll code. Its been provided by a third party. But i am able to call the functions successfully if I load the dll in a windows project. – RmP Aug 11 '15 at 11:49
  • Most likely not. Here's [Dependency walker](http://www.dependencywalker.com/) a graphical tool similar to _dumpbin_. You'll probably have to provide the code that creates the dll. – CristiFati Aug 11 '15 at 11:49
  • I tried Dependancy walker too. There are no functions listed there either and it gives me this warning. *Warning: At least one delay-load dependency module was not found. Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.* But how come it works fine for a windows app then. – RmP Aug 11 '15 at 11:52
  • 1
    A VB.NET class library project never has any exports. Calling vb.net code from unmanaged C++ code is a non-trivial operation, that C++ code needs to load and initialize the CLR first. And it has to do *something* to deal with the high likelihood that such code will throw an exception. Standard techniques are making the vb.net code [ComVisible] or hosting the CLR with IMetaData. Commonly used but a bad idea due to the very poor error reporting are writing a C++/CLI wrapper function that uses __declspec(export) and Giesecke's Unmanaged Exports library. – Hans Passant Aug 11 '15 at 12:01
  • Thank you @Hans . I understand now. You can put that in the answer section. I will mark it. – RmP Aug 11 '15 at 12:27

1 Answers1

0

Try writing before any function in your DLL file (header .h files) the name of the project with _API at the end (ECR_API).

for example, lets say we want to create a constructor and destructor for a class called Loader:

class Loader{
    public:
        ECR_API Loader();
        ECR_API ~Loader();
}

also dont forget to add export and import statements at the beggining of your header file:

#ifdef ECR_EXPORTS
#define ECR_API __declspec(dllexport)
#else
#define ECR __declspec(dllimport)
#endif

hope this helps! worked fine for me.

gever
  • 99
  • 1
  • 10