Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parameter on dlls

Status
Not open for further replies.

SiaMeX

Programmer
Jul 31, 2003
28
0
0
US
I know that this will be very easy for you guys...

Code:
'==========================================================
'MY VB CODE
'==========================================================
Private Declare Sub MyFunction Lib "MyDLL.dll" (ByVal MyParameter As String) As Integer

Private Sub TestFunc ()
    MyParameter = "Original String"
    MyFunction MyParameter 
    Msgbox MyParameter        -----> string should now be
                                                  "String Overwritten"
End Sub
===========================================================
After passing thru my MyFunction, the variable (MyPrameter) should now be overwritten by that previously called function. I have my Mydll.dll code below that i think there's something missing with it. Please help my with this code.

Code:
//=========================================================
//MyDll.dll in C/C++ CODE:
//=========================================================

#include ...
     .
     .
     .
int __declspec(dllexport) CALLBACK MyFunction (LPSTR MyParameter)
{
     strcpy (MyParameter, "Sting Overwritten");
     return 0;
}
//=========================================================

thank you so much!
 
Not 100% sure about this (I'm a little newer to C++ myself), but I believe that passing an LPSTR as a parameter passes it by val, not by reference - so, MyParameter in the c++ code would be a newly created LPSTR object based on the value of the MyParameter in the VB code (not a reference to it).

Try this:

Code:
//=========================================================
//MyDll.dll in C/C++ CODE:
//=========================================================

#include ...
     .
     .
     .
int __declspec(dllexport) CALLBACK MyFunction (LPSTR & MyParameter)
{
     MyParameter = "String Overwritten";
     return 0;
}
//=========================================================

Let me know if that does the trick (haven't tested it or anything - just the first thought off the top of my head).

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top