Sign in to follow this  
Followers 0
madhutm

calling c++ function

33 posts in this topic

i have one function in c++ thats connect with device via bluetooth.how can i call that function from autoit scripting?

Share this post


Link to post
Share on other sites



Hi,

Welcome to the autoit forum :)

I assume the function is in a library, so you have to use the DllCall function.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

hi

ths for reply.ya i am calling that function using calldll.But that not working fine. The function return type is bool every it will give different integer number($dll[0]) but it will not connected to the device.is there any prerequires to calling this type of functions.

Share this post


Link to post
Share on other sites

The function is like this in c++

Control(int ctl, byte[] inData, int inLen, byte[] outData, ref int outLen)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

$ctl = 0
 
$tStruct = DllStructCreate("byte[256]") ;set your byte size here
DllStructSetData($tStruct, 1, ...
 
$inLen = 0
 
$tStruct2 = DllStructCreate("byte[256]") ;set your byte size here
 
$outLen = 0
 
DllCall("yourlib.dll", "bool", "Control", "int", $ctl, "struct*", $tStruct, "int", $inLen, "struct*", $tStruct2, "int*", $outLen)
 
;Control(int ctl, byte[] inData, int inLen, byte[] outData, ref int outLen)
Not sure if it's a struct*, or if it's a ptr (in this case you will use DllStructGetPtr with the 1st element).

Edit: And you will maybe need a struct for the int pointer (I'm pretty sure about it though).

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

ths for reply.

i don't know about inside code in c++.same function i am calling from c# it works fine in c#.for testing purpose i need to call this function from autoit.

can you please tell me how to convert hex string to bytearray in Autoit. the above function second parameter i need to send this byte array only.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Here you go:

$b = StringToBinary("0x123ABC....")

$tStruct = DllStructCreate("byte[" & BinaryLen($b) & "]")
DllStructSetData($tStruct, 1, $b)
Br, FireFox. Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

hi

still it's giving different  integer number only. i am trying to connect blutooth device via com port.after taking com number i am conveting into hexstring then hexstring to bytearray.

ths

Share this post


Link to post
Share on other sites

this is how i am sending the function

  DllCall($dll,"bool:cdecl","BCRBT_Control","int", $ctl, "struct*", $tStruct, "int", $inLen, "struct*", $tStruct2, "int*", $outLen)

my paramer values are

        Local $input = GUICtrlRead($hInput)
        Local $dd =  StringFormat("%X",$input)
        Local $outLen = 0;
        Local $ctl =0xf901;
        $tStruct2 = DllStructCreate("byte[0xff]")
        $inLen =0;

        $b = StringToBinary($dd)
        $tStruct = DllStructCreate("byte[" & BinaryLen($B) & "]")
        DllStructSetData($tStruct, 1, $B)
 

Share this post


Link to post
Share on other sites

i am trying to connect blutooth device via com port.

Have you tried to communicate directly with the COM port?

An example >here.

If your struct2 is a simple byte (not a byte array), call the parameter with BYTE and directly 0xFF.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

hi,

that stringtobinary function not working properly.my port number is 30 after converting this to hexstring the value become 1E.while converting this value to binary that $b value gives  (0x313445)

but this is not binary format.

and struct2 is byte array.in c# i am declaring like this

byte[] = new byte[0xff];

how can i declare same like this in autoit.

and how can i find the tstruct lengh because i need to send this as third parameter to function.

ths

Share this post


Link to post
Share on other sites

that stringtobinary function not working properly.my port number is 30 after converting this to hexstring the value become 1E.while converting this value to binary that $b value gives  (0x313445)

but this is not binary format.

Binary is not 010101... it's hexadecimal in Binary variable type.

StringToBinary("0xABCDE") ;will be converted to binary type

and struct2 is byte array.in c# i am declaring like this

 

byte[] = new byte[0xff];

 

how can i declare same like this in autoit.

$tStruct2 = DllStructCreate("byte[" & 0xFF & "]") ;or 255

and how can i find the tstruct lengh because i need to send this as third parameter to function.

You haven't searched at all, take a look at the help file and you will find related function DllStructGetSize.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

after createng $struct2 i was trying to print that value like this

Msgbox(0,"text",$tStruct)

it'will showing nothing if it is wrong how can i print $tsturct.

Share this post


Link to post
Share on other sites

Please read the helpfile :


Return Value

Success: a variable for use with DllStruct calls

And check the examples.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

forgot above one for while this is my Bio_diconnect function it will not take any parameter.this one also not calling.

i am calling liki this

Local $ t1 = calldll($dll,"bool:cdecl","Bio_Disconnect")

msgbox(0,"txt",$t1[0])

this value give different integer numbers every time(not 0 or 1)

my question is there anything i need to setup working with bluetooth device or not.

Share this post


Link to post
Share on other sites

i print the @error it i will gives the 0 value.so i call the function successfully right.

ths

Share this post


Link to post
Share on other sites

Public bool Bio_Disconnect()

like this i call in c#

Share this post


Link to post
Share on other sites

sry

if(Bio_Disconnect){

............

}

this how exactly iam calling in c#

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0