Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dll's and strings...
#1
Ok Im new to FreeBASIC/QBASIC and come from Liberty BASIC and a bit from Pascal. Im messing around with making Dll's and it seems that it wont let me use string parameters...

Code:
'$include: 'win\kernel32.bi'
'$include: 'win\user32.bi'
function DllMain ( byval hModule as long, byval reason as long, byval lpReserved as long ) as integer

    select case reason
        case DLL_PROCESS_ATTACH
            hInstance = hModule
        
        case DLL_THREAD_ATTACH, DLL_THREAD_DETACH, DLL_PROCESS_DETACH
            
    end select
    
    DllMain = TRUE

end function
#endif
function LoadKcp (byval file$ as string, byval hdc as integer, byval x as integer, byval y as integer) as integer export
open file$ for input as #1
line input #1, widthP
line input #1, heightP
for x = sx to (widthP+sx)
for y = sy to (heightP+sy)
line input #1,colorP
SetPixel hdc,x,y,int(colorP*2)
next y
next x
close #1
LoadKcp=1
end function

Could you please tell me how to fix this?
adult swim]
Reply
#2
As in QB, if you use a suffix with a variable ($ in that case), you can't declare the full type ("as string"). FB will find a var declared w/o suffixes even if you use a suffix when referencing it.

Btw, take care if you are calling that dll function from other language than FB, because string types are not compatible -- FB 0.13 will support BYVAL string arguments (already added), so if the client exe calling the dll supports arguments declared as null-terminated strings, it will be fine.. with 0.12, you gotta declare it as "byval somestring as byte ptr", and access it as *somestring (* is used to dereference the pointer).
Reply
#3
Arg..Im sorry for being so ignorant but could you help me with this code...
Code:
'$include: 'win\gdi32.bi'
'$include: 'win\user32.bi'
'$include: 'win\kernel32.bi'
declare sub DisplayKcp (byval file as byte ptr,byval hDc as integer,byval sx as integer,byval sy as integer)
input file$
call DisplayKcp(file$,GetDC(HWND_DESKTOP),0,0)
sleep

sub DisplayKcp (byval file as byte ptr,byval hDc as integer,byval sx as integer,byval sy as integer)
open file for input as #1
line input #1, widthP$
line input #1, heightP$
wp=val(widthP$)+sx
hp=val(heightP$)+sy
dim colors(sx to wp,sy to hp)
for x = sx to wp
for y = sy to hp
line input #1,colorP$
colors(x,y) = val(colorP$)*10
next y
next x
close #1
for x = sx to wp
for y = sy to hp
call SetPixel(hDc,x,y,colors(x,y))
next y
next x
end sub
adult swim]
Reply
#4
I'm not real great at this stuff, but try in your Declare statement this:

Code:
declare sub DisplayKcp (byval file as string, byval hDc as integer,byval sx as integer,byval sy as integer)
Reply
#5
Hmm...Still does not work. :-?
adult swim]
Reply
#6
Untested, but should work...

Code:
'$include: 'win\gdi32.bi'
'$include: 'win\user32.bi'
'$include: 'win\kernel32.bi'
declare sub DisplayKcp (byval file as byte ptr,byval hDc as integer,byval sx as integer,byval sy as integer)
input file$
call DisplayKcp(file$,GetDC(HWND_DESKTOP),0,0)
sleep

sub DisplayKcp (byval file as byte ptr,byval hDc as integer,byval sx as integer,byval sy as integer)
dim sfile as string

sfile = *file

open sfile for input as #1
line input #1, widthP$
line input #1, heightP$
wp=val(widthP$)+sx
hp=val(heightP$)+sy
dim colors(sx to wp,sy to hp)
for x = sx to wp
for y = sy to hp
line input #1,colorP$
colors(x,y) = val(colorP$)*10
next y
next x
close #1
for x = sx to wp
for y = sy to hp
call SetPixel(hDc,x,y,colors(x,y))
next y
next x
end sub
Reply
#7
e.e; It does not. Type mismatch here...
Code:
call DisplayKcp(===>file$<===,GetDC(HWND_DESKTOP),0,0)
adult swim]
Reply
#8
Just declare the argument "byref someargname as string", if you are using it internally or calling it from a FB client, var-len strings can be used freely.
Reply
#9
This might be slightly off topic but I was wondering, since ByVal strings are supported now can they be allowed in optional arguments?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)