Page 1 of 1
Another call for help for C Code
Posted: Sat Sep 17, 2005 3:51 pm
by cecilcheah
Hi there
I am back with my Toolbook Problem. This time i would like to send a command to Toolbook (an external programme) and get some value back from Toolbook. From the nice programmers from the Toolbook company, i am able to get this code which is in C. I am no expert in C, can anyone please help me to translate this from C to PB.
Code: Select all
typedef struct TBMEVAL {
LPSTR lpExpression;
WORD wRetType;
LPSTR lpRetValue;
int nRetValueLength;
} TBMEVAL;
#define EVALTYPE_WORD 3
#define COMMAND "step im from 1 to %d;go to page i;end"
void stepPages(HWND,hwndMain) {
word wExecute = RegisterWindowMessage("TBM_EXECUTE");
word wEvaluate = RegisterWindowMessage("TBM_EVALUATE");
word wPages;
TBMEVAL Eval;
char Command[64];
Eval.lpExpression = "pageCount of this book";
Eval.wRetType = EVALTYPE_WORD;
Eval.lpRetValue = (LPVOID)%wPages;
if(!SendMessage(hwndMain,wEvaluate,TRUE,(LONG)(LPVOID)&EVAL))
return;
wsprintf(Command,COMMAND,wPages);
SendMessage(hwndMain,wExecute,TRUE,(LONG)(LPSTR)COMMAND);
}
Cecil
Re: Another call for help for C Code
Posted: Sat Sep 17, 2005 5:48 pm
by okasvi
Code: Select all
Structure TBMEVAL
lpExpression.l
wRetType.l
lpRetValue.l
nRetValueLength.l
EndStructure
#EVALTYPE_WORD 3
Procedure stepPages(HWND.l,hwndMain.l)
CRLF$ = Chr(13)+Chr(10)
COMMAND1.s = "step im from 1 to "
COMMAND2.s = CRLF$+"go to page i"+CRLF$+"end"+CRLF$
wExecute.l = RegisterWindowMessage_("TBM_EXECUTE")
wEvaluate.l = RegisterWindowMessage_("TBM_EVALUATE")
wPages.l
Eval.TBMEVAL
Eval\lpExpression = "pageCount of this book"
Eval\wRetType = #EVALTYPE_WORD
Eval\lpRetValue = @wPages
If SendMessage_(hwndMain, wEvaluate, #TRUE, EVAL) = #Null
ReturnProcedure
EndIf
SendMessage_(hwndMain, wExecute, #TRUE, COMMAND1+dPages+COMMAND2)
EndProcedure
i have NOT tested this since im not home... i hope this works

Re: Another call for help for C Code
Posted: Sat Sep 17, 2005 5:57 pm
by Truth_Seeker
EDIT: Heh, someone already posted (I took too long). His is probably better than mine.
cecilcheah wrote:Hi there
I am back with my Toolbook Problem. This time i would like to send a command to Toolbook (an external programme) and get some value back from Toolbook. From the nice programmers from the Toolbook company, i am able to get this code which is in C. I am no expert in C, can anyone please help me to translate this from C to PB.
Code: Select all
typedef struct TBMEVAL {
LPSTR lpExpression;
WORD wRetType;
LPSTR lpRetValue;
int nRetValueLength;
} TBMEVAL;
#define EVALTYPE_WORD 3
#define COMMAND "step im from 1 to %d;go to page i;end"
void stepPages(HWND,hwndMain) {
word wExecute = RegisterWindowMessage("TBM_EXECUTE");
word wEvaluate = RegisterWindowMessage("TBM_EVALUATE");
word wPages;
TBMEVAL Eval;
char Command[64];
Eval.lpExpression = "pageCount of this book";
Eval.wRetType = EVALTYPE_WORD;
Eval.lpRetValue = (LPVOID)%wPages;
if(!SendMessage(hwndMain,wEvaluate,TRUE,(LONG)(LPVOID)&EVAL))
return;
wsprintf(Command,COMMAND,wPages);
SendMessage(hwndMain,wExecute,TRUE,(LONG)(LPSTR)COMMAND);
}
Cecil
I know some C so I hope this is correct and can help:
Code: Select all
structure TBMEVAL
lpExpression.LPSTR
wRetType.w
lpRetValue.LPSTR
nRetValueLength.l
endstructure
#EVALTYPE_WORD = 3
#COMMAND = "step im from 1 to %d;go to page i;end"
procedure stepPages(HWND, hwndMain)
wExecute.w = RegisterWindowMessage_("TBM_EXECUTE")
wEvaluate.w = RegisterWindowMessage_("TBM_EVALUATE")
wPages.w
Eval.TBMEVAL
Dim Command.s(64)
Eval\lpExpression = "pageCount of this book"
Eval\wRetType = #EVALTYPE_WORD
Eval\lpRetValue = ; Do not know what this means: (LPVOID)%wPages;, I am assuming it is a type cast if so I am not sure how to do that in PB
If SendMessage_(hwndMain, wEvaluate, #True, ; Do not know what this means: (LONG)(LPVOID)&EVAL, I am assuming it is a type cast if so I am not sure how to do that in PB
endprocedure
I do not claim to be a master of PB or C so it probably is not totaly correct, I would like to think atleast some of it is correct.
Posted: Sat Sep 17, 2005 9:32 pm
by cecilcheah
There is some problem with th code, it is not returning anything from the procedure. Here is what i have changed to the code:
Code: Select all
Structure TBMEVAL
lpExpression.s
wRetType.l
lpRetValue.l
nRetValueLength.l
EndStructure
#EVALTYPE_WORD = 3
Procedure stepPages(hwnd)
CRLF$ = Chr(13)+Chr(10)
COMMAND1.s = "step i from 1 to 3;"
COMMAND2.s = CRLF$+"go to page i"+ ";"+"End"+CRLF$
wExecute.l = RegisterWindowMessage_("TBM_EXECUTE")
wEvaluate.l = RegisterWindowMessage_("TBM_EVALUATE")
wPages.l
Eval.TBMEVAL
Eval\lpExpression = "pageCount of this book"
Eval\wRetType = #EVALTYPE_WORD
Eval\lpRetValue = @wPages
MessageRequester("Str", COMMAND1+COMMAND2,0)
If SendMessage_(hwnd, wEvaluate, #TRUE, EVAL) = #Null
ProcedureReturn @wPages
EndIf
SendMessage_(hwnd, wExecute, #TRUE, COMMAND1+COMMAND2)
EndProcedure
OpenWindow(0, 0, 0, 300, 100, #PB_Window_SystemMenu, "Send Sender")
hWnd = FindWindow_(0, "ToolBook - TBJTester.tbk")
stepPages(hWnd)
MessageRequester("", Str(bResult),0)
Repeat
Select WaitWindowEvent()
Case #PB_EventCloseWindow: End
EndSelect
ForEver
The MessageRequester returns 4228160 where as it should be 3 (there are 3 pages in this external programme)
And how shall i translate this to PB:
Code: Select all
wsprintf(Command,"step i from 1 to %d;go to page i;end",wPages);
Cecil
Posted: Sat Sep 17, 2005 10:21 pm
by cecilcheah
On further debugging, this line is producing GPF:
Entire Code:
Code: Select all
Structure TBMEVAL
lpExpression.s
wRetType.l
lpRetValue.l
nRetValueLength.l
EndStructure
#EVALTYPE_WORD = 3
Procedure stepPages(hwnd)
CRLF$ = Chr(13)+Chr(10)
COMMAND1.s = "step i from 1 to 3;"
COMMAND2.s = CRLF$+"go to page i"+ ";"+"End"+CRLF$
wExecute.l = RegisterWindowMessage_("TBM_EXECUTE")
wEvaluate.l = RegisterWindowMessage_("TBM_EVALUATE")
wPages.l
Eval.TBMEVAL
Eval\lpExpression = "pageCount of this book"
Eval\wRetType = #EVALTYPE_WORD
MessageRequester("Str", COMMAND1+COMMAND2,0)
Eval\lpRetValue = @wPages
If SendMessage_(hwnd, wEvaluate, #TRUE, EVAL) = #Null
ProcedureReturn
EndIf
SendMessage_(hwnd, wExecute, #TRUE, COMMAND1+COMMAND2)
EndProcedure
OpenWindow(0, 0, 0, 300, 100, #PB_Window_SystemMenu, "Send Sender")
hWnd = FindWindow_(0, "ToolBook - TBKTester.tbk")
stepPages(hWnd)
MessageRequester("wpages", Str(@wPages),0)
Repeat
Select WaitWindowEvent()
Case #PB_EventCloseWindow: End
EndSelect
ForEver
Cecil
Posted: Sun Sep 18, 2005 12:42 am
by okasvi
it is hard(impossible) to fix this code without toolbook... so if it is freeware i could test it and see if i can fix it...
but i think this _might_ work...
Code: Select all
Structure TBMEVAL
lpExpression.s
wRetType.l
lpRetValue.l
nRetValueLength.l
EndStructure
#EVALTYPE_WORD = 3
Procedure stepPages(hwnd)
CRLF$ = Chr(13)+Chr(10)
COMMAND1.s = "step i from 1 to 3;"
COMMAND2.s = CRLF$+"go to page i"+ ";"+"End"+CRLF$
wExecute.l = RegisterWindowMessage_("TBM_EXECUTE")
wEvaluate.l = RegisterWindowMessage_("TBM_EVALUATE")
wPages.l
Eval.TBMEVAL
Eval\lpExpression = "pageCount of this book"
Eval\wRetType = #EVALTYPE_WORD
MessageRequester("Str", COMMAND1+COMMAND2,0)
Eval\lpRetValue = @wPages
If SendMessage_(hwnd, wEvaluate, #True, @Eval) = #Null ; i guess here you are supposed to give "pointer" to Eval structure, hence @ before Eval...
ProcedureReturn
EndIf
SendMessage_(hwnd, wExecute, #True, COMMAND1+COMMAND2)
EndProcedure
OpenWindow(0, 0, 0, 300, 100, #PB_Window_SystemMenu, "Send Sender")
hWnd = FindWindow_(0, "ToolBook - TBKTester.tbk")
stepPages(hWnd)
MessageRequester("wpages", Str(wPages),0) ; @ in front of variable gives you "pointer" to variable... and that is not what is needed
Repeat
Select WaitWindowEvent()
Case #PB_EventCloseWindow: End
EndSelect
ForEver
[/code]
Posted: Mon Sep 19, 2005 7:24 pm
by cecilcheah
Hi there
Thanks for helping, but it is still giving a GPF. I think there is a problem with Toolbook not really a 32 bit application. So i am looking for another solution.
If i use this, i can send the message (Command) to toolbook to do something. This has worked and tested. Now i would like to fetch the values return from Toolbook. Here is what i have so far.
Code: Select all
bResult = SendMessage_(hWnd, #WM_COPYDATA, #NULL, MyData) ; This will send the command to move a text field and return the new position of the text field inside MyData to Toolbook to do something.
Now to get the values back, i try this:
Code: Select all
DefWindowProc_(hWnd,#WM_COPYDATA,wParam,lParam)
While GetMessage_( @msgs, hWnd, 0, 0 ) > 0
If GetMessage_( @msgs, hWnd, 0, 0 ) = -1
MessageRequester("Error", "Stupid Error!", 0)
Else
TranslateMessage_(@msgs)
DispatchMessage_(@msgs)
EndIf
Wend
cc.s = Str(PeekW(@msgs\wparam))
MessageRequester("Str", cc , 0)
The problem here is, PB is waiting forever for toolbook to return something and get no reply from Toolbook. I know toolbook is receiving the message because i see the text field moved, and then PB just wait for Toolbook to return the message.
Am i doing something wrong here?
Cecil
Posted: Mon Sep 19, 2005 8:40 pm
by okasvi
so is toolbook freeware or not? its hard for me to test it without...
Posted: Mon Sep 19, 2005 8:48 pm
by cecilcheah
Another attempt to solve my problem, i put the whole window callback into a separate procedure and let PB due with it.
Code: Select all
Procedure WindowCallback(hWnd, Message, wParam, lParam)
Result = DefWindowProc_(hWnd, Message, wParam, lParam)
If Message = #WM_COPYDATA
msgs.MSG
While GetMessage_( @msgs, hWnd, 0, 0 ) > 0
TranslateMessage_(@msgs)
DispatchMessage_(@msgs)
PostQuitMessage_(0)
;Returnval = PeekW(@msgs\wparam)
MessageRequester("Error", Str(Result) , 0)
Wend
EndIf
ProcedureReturn Result
EndProcedure
Procedure TB_execute(hWnd, bSysSuspendOff, lpStatements.s)
....
bResult = SendMessage_(hWnd, #WM_COPYDATA, #NULL, MyData)
SetWindowCallback(@WindowCallback())
....
ProcedureReturn bResult
EndProcedure
Still i am getting nothing. It seems i have a problem with the Message in the WindowCallBack Procedure. PureBasic is not catching the Message #WM_COPYDATA at all, although in toolbook everything is moving as programmed in the MyData.
Am i doing something wrong here?
Cecil
Posted: Mon Sep 19, 2005 8:49 pm
by cecilcheah
No, Toolbook is not free. Do you need any more information about toolbook? Take a look here:
http://www.sumtotalsystems.com/
Cecil
Posted: Tue Sep 20, 2005 8:23 pm
by cecilcheah
How do i get this into a number:
WM_CLOSE = &H10
What is &H10 in number?
I am trying to see what message is passing into PB in here:
Code: Select all
Procedure WindowCallback(hWnd, Message, wParam, lParam)
Result = DefWindowProc_(hWnd, Message, wParam, lParam)
msgs.MSG
While GetMessage_( @msgs, 0, 0, 0 ) > 0
so i know why my code is not catching the #WM_COPYDATA, i am getting this number: 15,31,134. Is there any one of this number means #WM_COPYDATA?
Posted: Tue Sep 20, 2005 8:47 pm
by netmaestro
&H refers to a hexadecimal number, in this case 10, which evaluates to 16 in decimal terms. PureBasic uses the prefix $ to refer to a hex number, so you would write &H10 in PB as either $10 or 16.
To your second question, #WM_COPYDATA is equal to 74, as discovered with the line:
Debug #WM_COPYDATA
so #WM_COPYDATA is not found in the numbers you are getting in that windows message.
Posted: Tue Sep 20, 2005 9:07 pm
by cecilcheah
So what would 15 in terms of &H be ? &H9?
Posted: Tue Sep 20, 2005 9:44 pm
by Pupil
no &HF, there's a section in the PB reference manual about number bases and a table with all dec, bin, hex numbers from 0 to 255..