Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using API functions
#1
Hi, All!

1. I try to set QRichEdit (RapidQ basic) properties using API SendMessage function, calling from FB created dll.
FB DLL
[syntax="qbasic"] option explicit
#ifdef FB__WIN32
'$include: 'inc\win\kernel32.bi'
#endif

#define EM_SETBKGNDCOLOR 1091
#define WM_SETTEXT 12

Declare Function SendMessageA LIB "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, byref lParam As any ) As Integer

declare function CallDll lib "fromRQObjCall.dll" alias "CallDll" _
(byval SenderHandle as long, byval targetHAndle as long) as long

'$include: 'DllMain.bi'

'*********************'
function CallDll (byval SenderHandle as long, byval targetHAndle as long) as long export
dim zzz as integer, pzzz as long ptr
dim txt as string, saddtxt as byte ptr
dim ptxt as byte ptr

txt="12345" : saddtxt=sadd(txt) : ptxt=varptr(txt)
zzz=&h000000ff : pzzz=varptr(zzz)

CallDll=SendMessageA(targetHAndle, EM_SETBKGNDCOLOR, 0, &h000000ff )
CallDll=SendMessageA(targetHAndle, WM_SETTEXT, 0, "12345" )

end function
[/syntax]

targetHAndle - handle of RichEdit

Question1.
Why in user32.bi
Declare Function SendMessage Alias "SendMessageA" ....
without LIB "user32" ?

Question2.
If I use
CallDll=SendMessageA(targetHAndle, WM_SETTEXT, 0, "12345" )
- all works fine (and EM_SETBKGNDCOLOR too ),
but if I use
CallDll=SendMessageA(targetHAndle, WM_SETTEXT, 0, txt )
some garbage appears in RichEdit, not "12345" string
And EM_SETBKGNDCOLOR message not workin if I use variable, not value.

Thank you.
ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
Reply
#2
As far as the missing "user32" part goes.... near the top of the user32.bi you will find the line

#inclib "user32"

This allows you to drop the LIB part of the declare statement. This is nice if you have a lot of functions to declare from the same library.

For the second part, someelse will have to help you with that part. Sad
Reply
#3
Quote:As far as the missing "user32" part goes.... near the top of the user32.bi you will find the line

#inclib "user32"

This allows you to drop the LIB part of the declare statement. This is nice if you have a lot of functions to declare from the same library.

For the second part, someelse will have to help you with that part. Sad
Thanks.
Well.. If I use some functions from several dll files, can I write something like:
#inclib "user32"
#inclib "gdi32"
And then
declare function [from user32]
declare function [from gdi32]
etc
Or I need
#inclib "user32"
declare function [from user32]

#inclib "gdi32"
declare function [from gdi32]


About Question2
I think if it's possible to realize mixing RapidQ-FreeBasic programming -
this will be "amazing" thing.
RapidQ GUI power and FreeBasic fast routines- yeah, it's programmer dream Smile
ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
Reply
#4
Dazed And Confused...

Declare Function SendMessageA LIB "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, byref lParam As any ) As Integer
[...]

dim txt as string, saddtxt as byte ptr
txt="12345" : saddtxt=sadd(txt)
zzz=&h000000ff :

CallDll=SendMessageA(targetHAndle, EM_SETBKGNDCOLOR, 0, byval zzz )
CallDll=SendMessageA(targetHAndle, WM_SETTEXT, 0, byval saddtxt)

And all working fine!
ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
Reply
#5
SendMessage is the API function that caused more troubles until now ;)

As in VB/PB, for any argument declared as "BYREF AS ANY", you have to use BYVAL to pass pointers, constants or strings as parameter -- you don't have to use sadd/strptr() with strings, just use "BYVAL mystring".
Reply
#6
Quote:SendMessage is the API function that caused more troubles until now Wink

As in VB/PB, for any argument declared as "BYREF AS ANY", you have to use BYVAL to pass pointers, constants or strings as parameter -- you don't have to use sadd/strptr() with strings, just use "BYVAL mystring".

It's working! :lol:
Thank you!
ith best regards, Andrew Shelkovenko.
http://www.wildgardenseed.com/RQDP/FreeBasic/index.html - FreeBasic documentation Project
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)