wpf - How to call C++ DLL function from VB? -


i need call function c++ dll (bvrelate.dll) through visual basic (vbwpf).

c++ dll code:

//vbrelate.h  #ifdef vbrelate_exports #define vbrelate_api __declspec(dllexport) #else #define vbrelate_api __declspec(dllimport) #endif  extern vbrelate_api void dosomething();  //vbrelate.cpp  #include <atlstr.h> #include "vbrelate.h"  vbrelate_api void dosomething() {     cstring stroutput("hello world");     messagebox(null, stroutput, l"got message", mb_ok); } 

then try call function vb (wpf project)

imports system.runtime.interopservices class mainwindow     declare function dosomething lib "m:\vbrelate.dll" ()     private sub button_click(sender object, e routedeventargs) handles button.click         dosomething()     end sub end class 

and got exception:

"marshaldirectiveexception unhandled". unhandled exception of type 'system.runtime.interopservices.marshaldirectiveexception' occurred in vbwpf.exe

then used dumpbin:

dumpbin /exports "m:\vbrelate.dll">m:\vbrelate.txt 

and in vbrelate.txt this:

microsoft (r) coff/pe dumper version 10.00.40219.01 copyright (c) microsoft corporation.  rights reserved.   dump of file m:\vbrelate.dll  file type: dll    section contains following exports vbrelate.dll      00000000 characteristics     57e3dda6 time date stamp thu sep 22 16:33:26 2016         0.00 version            1 ordinal base            1 number of functions            1 number of names      ordinal hint rva      name            1    0 00011299 ?dosomething@@yaxxz = @ilt+660(?dosomething@@yaxxz)    summary          1000 .00cfg         4000 .data         1000 .gfids         1000 .idata         4000 .rdata         1000 .reloc         1000 .rsrc        10000 .text        10000 .textbss         1000 .tls 

then trying use def file, not understand how use (where should - dll file, project files or somewhere else) , why should use while using __declspec (not __stdcall). put def file in directory dll file, , dll projects files:

; vbrelate.def - defines exports vbrelate.dll  library vbrelate.dll description 'a c++ dll can called vb'  exports     dosomething 

then rebuilt dll. didn't work. same exception appeared. , dumpbin returned same dump, nothing changed.

the problem not appear within dll/native c++ code, although maybe if made managed c++ dll? exception saying there wrong handling data between managed (vb) , unmanaged (c++) code: marshaldirectiveexception on msdn

it may possible change attributes using marshalasattribute() msdn


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -