What's new

VB to C++

Doomulation

?????????????????????????
I know it's possible to call c++ functions from VB. Especially self-made ones.
However, no matter how i try now, i can't get it to work.
Basically, i'm trying to send a string to a c++ dll function.
But the result is that the function doesn't recieve it.

C++ Code:
PHP:
extern "C" int PASCAL EXPORT Bah(char* test)
{
  MessageBox(0,(LPCTSTR)test,"",MB_OK);
  return 0;
}

VB Code:
PHP:
Private Declare Sub Bah Lib "..." (str as String)
Private Sub Form_Load()
  Bah "test"
End Sub

Whatever i try to send, it isn't recieved by the c++ function. It's always the same data that you get. There's no problem compiling or linking the project.

Any tips? Any suggestions? Any help? Anyone know?
 

Cyberman

Moderator
Moderator
I suggest making a function that returns a string first instead of passing a string. Another thing that might be wise is to have a way to verify the DLL is loaded. For exampple

Code:
extern_"C"_int_PASCAL_EXPORT_BahThere(void)
{
 return 1;
}
Or something like that.
If it doesn't return 1 then you know there is a problem.

Cyb
 

icepir8

Moderator
Try changing your vb code to this.

Vb will not pass strings right unless you do this.

Private Declare Sub Bah Lib "..." (ByVar str as String)
Private Sub Form_Load()
Bah "test"
End Sub
 

Eagle

aka Alshain
Moderator
icepir8 said:
Try changing your vb code to this.

Vb will not pass strings right unless you do this.

Private Declare Sub Bah Lib "..." (ByVar str as String)
Private Sub Form_Load()
Bah "test"
End Sub

I could be wrong but shouldnt that be "ByVal". I've never seen a ByVar keyword.
 

Top