1 Replies - 20280 Views - Last Post: 10 June 2010 - 03:46 AM Rate Topic: -----

#1 herk   User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 20
  • Joined: 29-March 09

[VBScript] Call function from C++ DLL library from VBScript

Posted 10 June 2010 - 01:41 AM

Hello everyone.

At the beginning I want to point that I'm not VBS developer ;-). My programming language is C++ so this is the reason why I'm asking You form help.

I have my own DLL library ( function from DLL is exported with __stdcall standard ).

Now I need to call function from this DLL library from VBScript.


On CodeProject page I found topic, describing how to call function from DLL using VBS

Here is a link : http://www.codeproje...ll/XDllPt2.aspx

And here is a code :

Private Declare Function GetCpuSpeed Lib "DLL2.dll" () As Integer
Private Declare Sub InitCommonControls Lib "comctl32.dll" ()

Private Sub Form_Initialize()
    InitCommonControls
    ChDir App.Path

End Sub

Private Sub Command1_Click()

    Dim nSpeed As Integer
    Dim s As String
    
    Screen.MousePointer = vbHourglass
    nSpeed = GetCpuSpeed()
    Screen.MousePointer = 0
    
    s = nSpeed
    
    Form1.Text1.Text = "GetCpuSpeed() returned " + s

End Sub

Private Sub Form_Load()

    Form1.Text1.Text = ""
    
End Sub



But when I try to launch this example code I have error like below :

Line : 1
Error : Expected end of statement

I'm completely newbie in VBS so if You can show me the way how to solve this problem I will be grateful.

Greetings.

Mateusz

This post has been edited by herk: 10 June 2010 - 01:42 AM


Is This A Good Question/Topic? 0
  • +

Replies To: [VBScript] Call function from C++ DLL library from VBScript

#2 raziel_   User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,281
  • Joined: 25-March 09

Re: [VBScript] Call function from C++ DLL library from VBScript

Posted 10 June 2010 - 03:46 AM

hi :)
in VBS you can not explicitly declare types. that is why you get the error. the article you show he call the dll in vb6 where you can do such things. maybe if you try passing your result to a pointer in the function not to return result you can bypass this. what i mean is this change the function in the dll to return the result to a pointer in the declaration something like so:
DLL2_API void __stdcall GetCpuSpeed(int *P)
{
    const unsigned __int64 ui64StartCycle = GetCycleCount();
    Sleep(1000);
    *P= static_cast((GetCycleCount() - ui64StartCycle) / 1000000);
}



now in your VBS call it like so:
Private Declare Function GetCpuSpeed Lib "DLL2.dll" (ByRef P As Integer)
...



hope this will help you :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1