Archive: How to use System::Call "rapi::CeRapiInitEx...


How to use System::Call "rapi::CeRapiInitEx...
I am trying to detect if a device is connected via activesync by using the System.dl call to CeRapiInitEx. Apparently I do not understand how to allocate memory for the structure required by this function.

The struct is as follows:

public struct RAPIINIT
{
public int cbsize;
public IntPtr heRapiInit;
public UInt32 hrRapiInit;
};

HRESULT CeRapiInitEX(RAPIINIT)

Here is my failed attempt so far (any help is appreciated)

System::Call "*(i 12, i, i) i .s"
Pop $1
System::Call "rapi::CeRapiInitEX(i r1) i .r0"
DetailPrint "CeRapiInitEX Status: $0"
DetailPrint "Struct Pointer: $1"
System::Call "*$1(i .r2, i .r3, i .r4)"
System::Free $1
DetailPrint "cbSize: $2"
DetailPrint "heRapiInit: $3"
DetailPrint "hrRapiInit: $4"


are you sure its not CeRapiInitEx ?


Yes you are correct - it is CeRapiInitEx

Ultimately I want to test the return value for success and then wait for the connection signal from kernel32::WaitForSingleObject


What exactly doesn't work and how?


I think I've got it figured out. (see below) What I was struggling with were the data types of the components of the struct and the values of the return variables. It seems that all the Microsoft docs assume that the definitions of things like S_OK are universally known. Since I am a noob with RAPI and in the NSIS scriptiong environment I don't have the headers that define S_OK, S_FAIL , etc. I was not sure what to look for in the return variable.

Anywhooo this seems to be working. Thanks for your response.

CheckConnect:
MessageBox MB_OK "Put PPC in Cradle"
System::Call "*(i 12, i, i) l .s"
Pop $1
System::Call "rapi::CeRapiInitEx(l r1) i .s"
Pop $0
DetailPrint "CeRapiInitEx Return Value: $0"
DetailPrint "Struct Pointer: $1"
System::Call "*$1(i .r2, i .r3, i .r4)"
System::Free $1
DetailPrint "cbSize: $2"
DetailPrint "heRapiInit Handle: $3"
DetailPrint "hrRapiInit Return Value: $4"
${If} $4 == 0
DetailPrint "Waiting for Signal..."
System::Call "Kernel32::WaitForSingleObject(i r3, l 300) i .r5"
DetailPrint "WaitForSingleObject Return Value: $5"
${Else}
System::Call "rapi::CeRapiUninit() i. s"
Pop $1
DetailPrint "CeRapiUninit Return Value: $1"
Goto CheckConnect
${EndIf}


for most symbols like that, just google "define FOOBAR_SYMBOL" if you don't have the MS headers handy