Page 2 of 2

Posted: Wed Jul 10, 2002 2:35 pm
by BackupUser
Restored from previous forum. Originally posted by Shawn.

Hi.

I am trying the COM interface to the dll (which turned out to be CDECL). I have got it to work using VBScript. My PB version crashes though on the first line with CallCOM in it.

It is possible that I don't have the method numbers correct. How would I verify the method numbers? I have the header file, but am not sure what to look for.

Thanks.

Shawn

Code: Select all

 
'VBScript version that works:
 
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set SabreTerm = CreateObject("COMCSAPISession.COMCSAPISession.1")
    
    bResult = SabreTerm.ConnectToHostSession("FIXEDOFEPSABRE")
    iLastRetCode = SabreTerm.GetLastReturnCode()
    If iLastRetCode = 0 Then
        WshShell.Popup "Connected"
	SabreTerm.DisconnectFromHostSession()
    Else 
        WshShell.Popup "Not Connected"
    End If
 
 
;PB version that doesn't work
 
#ConnectToHostSession = 0
#DisconnectFromHostSession = 1
#GetLastReturnCode = 4
CallCOM(#ConnectToHostSession,"COMCSAPISession.COMCSAPISession.1", "FIXEDOFEPSABRE")
iLastRetCode.b = CallCOM(#GetLastReturnCode, "COMCSAPISession.COMCSAPISession.1")
If iLastRetCode = 0
  MessageRequester("",Str(iLastRetCode)+" Connected", 0)
  CallCOM(#DisconnectFromHostSession,"COMCSAPISession.COMCSAPISession.1")
Else
  MessageRequester("",Str(iLastRetCode)+"Error", 0)
EndIf




Edited by - shawn on 10 July 2002 15:38:05

Edited by - shawn on 10 July 2002 15:40:39

Posted: Wed Jul 10, 2002 3:23 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

There may be more errors, but one thing is clear: you're using wrong values as method constants.

If you have a list with the methods (in the correct order, and including the first three that are common to all objects), you must multiply its position in the list by four (starting in 0).

For example, if you have this method list for the COMCSAPISession object:

Method0(don't remember its name)
Method1(don't remember its name)
Method2(don't remember its name)
ConnectToHostSession
DisconnectFromHostSession

Then, numbers should be:

#ConnectToHostSession = 12
#DisconnectFromHostSession = 16

And maybe you shouldn't give the resulting value of a function call to a byte variable:

Code: Select all

iLastRetCode.b = CallCOM(#GetLastReturnCode, "COMCSAPISession.COMCSAPISession.1")
Unless Danilo corrects me. Hope this helps, bye,


El_Choni

Edited by - El_Choni on 10 July 2002 16:29:27

Posted: Wed Jul 10, 2002 4:16 pm
by BackupUser
Restored from previous forum. Originally posted by Shawn.

Is there another way to find the method numbers, or refer to the methods by name?

I tried, sanely, using the calculation to determine the correct method numbers, then, rather insanely, tried multiples of 4 up to 100, then from 0 to 70, but it still crashes at the first CallCOM line.

Thanks.

Shawn

Posted: Wed Jul 10, 2002 4:23 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

I may be wrong, I don't know too much about COM but shouldn't you create the object before using it? There must be an equivalent to CreateObject("COMCSAPISession.COMCSAPISession.1"). I think you must use CoCreateInstance_(), but that's beyond my knowledge, sorry.

El_Choni

Posted: Wed Jul 10, 2002 5:06 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.

If i'm not completely lost here the CDECL dll expects your program to empty the stack, so i'm thinking that shouldn't it be possible on the PureBasic side, in assembler, to POP the stack and thus return the stack to it's original state?
Fred, Danilo anyone with some assembler knowlege, is it possible/correct to do it this way?

Well if i'm not completely wrong you could put these lines right after the CallFunction() command, the assembly option must be enabled in the compiler:

Code: Select all

...
CallFunction(#id,"FunctionName", arg1, arg2)
POP eax ; pop arg1
POP eax ; pop arg2 stack should now be OK
...
This is just a guess on my side, but it shouldn't take too much time to test if it is working.

Good luck with your project!

Posted: Wed Jul 10, 2002 5:37 pm
by BackupUser
Restored from previous forum. Originally posted by Shawn.
If i'm not completely lost here the CDECL dll expects your program to empty the stack, so i'm thinking that shouldn't it be possible on the PureBasic side, in assembler, to POP the stack and thus return the stack to it's original state?
Fred, Danilo anyone with some assembler knowlege, is it possible/correct to do it this way?

Well if i'm not completely wrong you could put these lines right after the CallFunction() command, the assembly option must be enabled in the compiler:

Code: Select all

...
CallFunction(#id,"FunctionName", arg1, arg2)
POP eax ; pop arg1
POP eax ; pop arg2 stack should now be OK
...
Cool! My program doesn't crash anymore.

The only problem is that the result (long) that the function returns disappears after the first POP eax. Is there anyway to save it, clear the stack, then put it back again?

Thanks.

Shawn

Posted: Wed Jul 10, 2002 5:40 pm
by BackupUser
Restored from previous forum. Originally posted by Shawn.
I may be wrong, I don't know too much about COM but shouldn't you create the object before using it? There must be an equivalent to CreateObject("COMCSAPISession.COMCSAPISession.1"). I think you must use CoCreateInstance_(), but that's beyond my knowledge, sorry.

El_Choni
Looks to be true. There is a post in Tips and Tricks called "OOP/COM Programming with PB -- Taskbar" that explains it.

Now I just have to study it.

Thanks.

Shawn

Posted: Wed Jul 10, 2002 5:49 pm
by BackupUser
Restored from previous forum. Originally posted by Shawn.
If i'm not completely lost here the CDECL dll expects your program to empty the stack, so i'm thinking that shouldn't it be possible on the PureBasic side, in assembler, to POP the stack and thus return the stack to it's original state?
Fred, Danilo anyone with some assembler knowlege, is it possible/correct to do it this way?

Well if i'm not completely wrong you could put these lines right after the CallFunction() command, the assembly option must be enabled in the compiler:

Code: Select all

...
CallFunction(#id,"FunctionName", arg1, arg2)
POP eax ; pop arg1
POP eax ; pop arg2 stack should now be OK
...
Cool! My program doesn't crash anymore.

The only problem is that the result (long) that the function returns disappears after the first POP eax. Is there anyway to save it, clear the stack, then put it back again?

Thanks.

Shawn

My mistake. I didn't put the pop eax's right after the function, and it wasn't the function result that disappeared, it was my result variable. Oh boy - late for lunch I guess - brain is starved.

Seems to work!

Thanks.

Shawn

Posted: Wed Jul 10, 2002 6:03 pm
by BackupUser
Restored from previous forum. Originally posted by Shawn.

Hi.

Thanks everyone for your help on this.

Now I can start the project!

Thanks again - I learned alot.

Shawn

Posted: Wed Jul 10, 2002 6:05 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Seems to work!
Seems i wasn't totally lost after all :)

Posted: Wed Jul 10, 2002 7:53 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

Where did you find this CDECL DLL ? . A cleaner way to set up the stack correctly is to use the ADD command:

ADD esp, 8 ; Like the 2 POP. 4x2 (4xNbArgs)


Fred - AlphaSND

Posted: Wed Jul 10, 2002 8:09 pm
by BackupUser
Restored from previous forum. Originally posted by Shawn.
Where did you find this CDECL DLL ? . A cleaner way to set up the stack correctly is to use the ADD command:

ADD esp, 8 ; Like the 2 POP. 4x2 (4xNbArgs)


Fred - AlphaSND
Yup - It works!

Thanks.

Shawn