PDA

View Full Version : VB to C++



Doomulation
December 22nd, 2002, 16:16
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:


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


VB Code:


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
December 22nd, 2002, 19:24
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



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
December 23rd, 2002, 09:07
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
December 23rd, 2002, 16:04
Originally posted by icepir8
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.

icepir8
December 23rd, 2002, 16:52
Yep. ByVal is correct.
:blush:

Doomulation
December 23rd, 2002, 23:16
You're right, that was it.
Lol, never thought of that.