Sign in to follow this  
Followers 0
/dev/null

Array as func parameter ?

4 posts in this topic

#1 ·  Posted (edited)

Hi gurus,

I'm trying to change the code of the UPD functions in the following way and need some help. UDPOpen shall return an array with the following structure:

$UDPsocket = UDPOpen("127.0.0.1", 65432)

;$UDPsocket[0] = real socket 
;$UDPsocket[1] = IP Address
;$UDPsocket[2] = Port Number

Then UDPSend will use this "socket" to send some data.

$ret = UDPSend($UDPsocket,$data)

Now, I did the following in UDPOpen.

AUT_RESULT AutoIt_Script::F_UDPOpen(VectorVariant &vParams, Variant &vResult)
{
    Variant     *pvTemp;
           
    Util_VariantArrayDim(&vResult, 3);

    SOCKET m_socket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
    if ( m_socket == INVALID_SOCKET )
    {
    SetFuncErrorCode(WSAGetLastError());
        pvTemp = Util_VariantArrayGetRef(&vResult, 0);
        *pvTemp = (int) INVALID_SOCKET;
    }

    // Create the return structure [0] = socket; [1] = IP Addr; [2] = Port
    pvTemp = Util_VariantArrayGetRef(&vResult, 0);
    *pvTemp = (int) m_socket;
    pvTemp = Util_VariantArrayGetRef(&vResult, 1);
    *pvTemp = vParams[0].szValue();
    pvTemp = Util_VariantArrayGetRef(&vResult, 2);
    *pvTemp = vParams[1].szValue();
    
       return AUT_OK;

} // UDPOpen()

I guess this should be O.K., as I cheated from F_StringSplit :)

Now, I'm trying the read from the Array in UDPSend() where I tried this:

AUT_RESULT AutoIt_Script::F_UDPSend(VectorVariant &vParams, Variant &vResult)

{
    Variant     *pvTemp;
    
    pvTemp = Util_VariantArrayGetRef(&vParams[0], 0);

    SOCKET m_socket = (SOCKET) &pvTemp; // <== IS THIS CORRECT? 
    int nRet;

    // Connect to a server.
    SOCKADDR_IN to;

    to.sin_family = AF_INET;
    
    pvTemp = Util_VariantArrayGetRef(&vParams[0], 1);
    to.sin_addr.s_addr = inet_addr( &pvTemp ); // <== THIS GENERATES AN ERROR
;

However, I do get the following compile time error:

73 G:\autoitsrc\src\script_udp.cpp cannot convert `Variant**' to `const char*' for argument `1' to `long unsigned int inet_addr(const char*)'

So, there is clearly a type mismatch, but I don't know enough about the internal data structures to figure out how to fix this. Could someone please shed some light on this?

Or expressed more clearly: How can I read from &vParams[0], which contains itself an array? In UDPSend &vParams[0] will be the "socket structure/array" and &vParams[1] will be the data to send. Unfortunately I could not find a AutoIT function that uses an array as one of the parameters, where I could have cheated from :evil:

Thanks!

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm Just simply searching in the forum for no reason... I Don't know auto-it script very well... but i KNow C++ :evil:

Maby you allready fixed the problem becuasse now it is 2 weeks ago you posted it...

but i give it a try :D

SOCKET m_socket = (SOCKET) &pvTemp

your casting a address of a pointer and put it into M_socket....

that's not right I think you mean:

SOCKET m_socket = (SOCKET) *pvTemp

inet_addr( &pvTemp );

Your now passing a double pointer to inet_addr :)

maby this should change into

inet_addr(pvTemp);

But i don't know for sure becausse i don't know what Util_VariantArrayGetRef

returns...

Edited by godomega

Share this post


Link to post
Share on other sites

....

However, I do get the following compile time error:

73 G:\autoitsrc\src\script_udp.cpp cannot convert `Variant**' to `const char*' for argument `1' to `long unsigned int inet_addr(const char*)'

...

<{POST_SNAPBACK}>

Kurt,

The problem is that you use 'double addressing'. Util_VariantArrayGetRef() already returns a 'pointer' to the variant, so there is no need to get the address of this pointer again. Just remove the &'s and do some proper type conversion:

SOCKET m_socket = (SOCKET) pvTemp.nvalue();

to.sin_addr.s_addr = inet_addr( pvTemp.szValue() );

Regards,

-Sven

Share this post


Link to post
Share on other sites

Hi guys,

sorry for the late reply, I have been in switzerland for some days ...

Thanks for the help. In the meantime I was able to figure out my mistake and

the new UDP functions are part of Beta 56. Many thanks to JPM.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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