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

Posted on 2004-11-03
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
    LVL 26

    Accepted Solution

    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

    by the way, how do you declare your function in VB?
    LVL 2

    Expert Comment

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    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…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now