   combining Visual C++ and Visual Basic: Bad DLL calling convention
  Im trying to combin Visual C++ and Visual Basic. I create a dll in visual C++, with this source:#include <windows.h>extern "C" __declspec(dllexport) void ThrowMessage(char* msg);void ThrowMessage(char* msg){MessageBox(0, (char*)msg, "", 0);}Then, I build a visual basic program, with the source:Private Declare Function ThrowMessage Lib "G:\C++\Socket\Release\Socket.dll" (Msg As String)Private Sub Form_Load()    ThrowMessage "test"End SubWhen I do this, I first get an empty messagebox, and then an error message with the text "Bad DLL calling convention".Now my first question:I assume you can''t pass char* as a string in visual basic. So what should I change the "char*" in so that visual basic can pass a stringQuestion #2:How can I make sure the error message "Bad DLL calling convention" doesn''t appear.10x,H4ck3r  
  Use BSTR for the strings.;  It''s been a while since I made a .dll for VB but don''t you need byref?Heres what I think it should be (Don''t hold it to me though )Private Declare Sub ThrowMessage Lib "G:\C++\Socket\Release\Socket.dll" (Byref Msg As String)    -UltimaX-"You wished for a white christmas... Now go shovel your wishes!"  ;  10x for ur help, but:ByRef isn''t required, I think. It doesnt work with it either .Ive read somewhere that I have to edit the ***.def file, but that file doesn''t exist.  ;  First off, you do use a char*.Second, VB uses __stdcall for calling into dlls. So your function definition is:extern "C" __declspec(dllexport) __stdcall void ThrowMessage(char* msg);(You might need to reorder the modifiers a bit);  I compiled. 2 error(s), 2 warning(s):warning C4518: ''void '' : storage-class or type specifier(s) unexpected here; ignoredwarning C4230: anachronism used : modifiers/qualifiers interspersed, qualifier ignorederror C2556: ''void __cdecl ThrowMessage(char *)'' : overloaded function differs only by return type from ''int __stdcall ThrowMessage(char *)''   G:\C++\Socket\Socket.cpp(3) : see declaration of ''ThrowMessage''error C2373: ''ThrowMessage'' : redefinition; different type modifiers   G:\C++\Socket\Socket.cpp(3) : see declaration of ''ThrowMessage''Error executing cl.exe.Any ideas? (Ill play arround a bit now)  ;  sorry about that. It''s a while since I did any of this VB. i''ll have a look around for you...  ;  OK: got it. It''s:extern "C" __declspec(dllexport) void __stdcall ThrowMessage(char *msg)So your code needs to become:#include <windows.h>extern "C" __declspec(dllexport) void __stdcall ThrowMessage(char *msg);void __stdcall ThrowMessage(char *msg){    MessageBox(....);}  ;  Tried that, and it compiles, but in Visual Basic it throws the error message "Can''t find DLL entry point ThrowMessage in G:\C++\Socket\Release\Socket.dll".  ;  Sorry. My bad. Remove extern "C".[edit] I'm mostly working from months-old memories here...don't have VB installed at the moment.[edited by - tr0n on May 10, 2003 1:38:21 PM]