Can't call C++ function in DLL from VB

Posted on 2004-11-03
Medium Priority
Last Modified: 2008-02-01
I have a VB code that utilizes a couple of functions in a C++ DLL.  In one place my function call works in the other I get a "Compile Error: Invalid use of property" error.
Here is my VB code:

Private Sub ChangeItemNameValue_Click()
Dim itemName, itemValue As String

If TItemName.Text <> "" And TItemValue.Text <> "" Then
    itemName = TItemName.Text
    itemValue = TItemValue.Text
    Call ChangeItem(itemName, itemValue)    '<-------------- Here it works fine
    MsgBox ("You must set the Item Name and Value")
End If
End Sub

Private Sub ChangeOrientation_Click()
Dim X1, X2, Y1, Y2 As String
If Tx1.Text <> "" And Tx2.Text <> "" And Ty1.Text <> "" And Ty2.Text <> "" Then
    X1 = Tx1.Text
    X2 = Tx2.Text
    Y1 = Ty1.Text
    Y2 = Ty2.Text
Call ChangeOrientation(X1, Y1, X2, Y2)        '<-------------- Here I get the error
    MsgBox ("You must set all four cordinate values")
End If
End Sub

Here is my C++ code from the DLL for both:

__declspec(dllexport) _stdcall ChangeItem(BSTR itemName, BSTR itemValue)


    LASER_PACKET                packet;
    packet.timestamp = getTimeDouble();
    packet.type      = LaserPacketChangeItemValue;
    itemP = (PACKET_CHANGE_ITEM_VALUE*)packet.dataP;

    strcpy(itemP->itemName, (OLE2A(itemName)));
    strcpy(itemP->itemValue, (OLE2A(itemValue)));
    tcpClientG.sendData((char*)&packet, sizeof(packet)-(MAX_COMMAND_SIZE-sizeof(PACKET_CHANGE_ITEM_VALUE)));
    currentCommandStatusG = LaserCommandPending;

__declspec(dllexport) void _stdcall ChangeOrientation(BSTR x1Cordinate, BSTR y1Cordinate, BSTR x2Cordinate, BSTR y2Cordinate)

     LASER_PACKET                      packet;

    packet.timestamp = getTimeDouble();
    packet.type      = LaserPacketChangeItemOrientation;
    itemP = (PACKET_CHANGE_ITEM_ORIENTATION*)packet.dataP;
    itemP->x1 = atoi(OLE2A(x1Cordinate));
    itemP->x2 = atoi(OLE2A(x2Cordinate));
    itemP->y1 = atoi(OLE2A(y1Cordinate));
    itemP->y2 = atoi(OLE2A(y1Cordinate));
    tcpClientG.sendData((char*)&packet, sizeof(packet)-(MAX_COMMAND_SIZE-sizeof  (PACKET_CHANGE_ITEM_ORIENTATION)));
    currentCommandStatusG = LaserCommandPending;

Any help would be greatly appreciated!

Question by:axnst2
  • 2
LVL 26

Accepted Solution

EDDYKT earned 2000 total points
ID: 12486880
change this

Dim itemName, itemValue As String

Dim X1, X2, Y1, Y2 As String


Dim itemName As String, itemValue As String

Dim X1 As String, X2 As String, Y1 As String, Y2 As String

LVL 26

Expert Comment

ID: 12486893
by the way, how do you declare your function in VB?

Expert Comment

ID: 12487433
instead of the BSTR you might consider something like this
LONG __stdcall  CreateList(LPSTR  sListName);

in vb
Public Declare Function CreateList Lib "yourdllname.dll" Alias "?CreateList@@YGJPAD@Z" (ByVal sListName As String) As Long

Yuo need the fully decorated name which you get using dependency walker a tool of C++

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month17 days, 1 hour left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question