Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

calling a DLL

 [1/6] from: belkasri::1stlegal::com at: 11-Jul-2002 17:37


I am trying to call a DLL from REBOL. I load the library, create the routine (make routine!) ...all the rest seems to work fine. I have a problem with the parameter to pass: The DLL is expecting a structure of this nature: #define Max 41 struct loc-data { char name[Max]; float lat; float lon; .... } On the REBOL side, I have: loc-data: make struct! [ name [string!] lat [decimal!] lon [decimal!] .... ] [ Dallas, TX 32.7941 -96.765 .... ] Then I make the routine: my-routine: make routine! [ arguments passed to the structure loc-data return: [long] ] clib "Func-I-Am-Calling" it seems not to like loc-data structure, possibly because char name[41] is not really the same as: name [string!] What's wrong? and how to fix it? Thanks. --Abdel.

 [2/6] from: greggirwin:mindspring at: 11-Jul-2002 17:40


Hi Abdel, Have you tried something like this? my-routine: make routine! compose/deep [ "arguments passed to the structure" data-struct [struct! [(first loc-data)]] return: [integer!] ] clib "Func-I-Am-Calling" --Gregg

 [3/6] from: belkasri:1stlegal at: 12-Jul-2002 9:15


Greg, I have tried what you sugested. << Have you tried something like this? my-routine: make routine! compose/deep [ "arguments passed to the structure" data-struct [struct! [(first loc-data)]] return: [integer!] ] clib "Func-I-Am-Calling"
>>
It does not return an error, but it also does not return the control at all! Now it hangs forever! --Abdel.

 [4/6] from: greggirwin:mindspring at: 12-Jul-2002 9:11


Hi Abdel, << it seems not to like loc-data structure, possibly because char name[41] >> Have you tried initializing loc-data/name to a string of 41 characters, with or without a null terminator, before making the call? Have you tried [char*], instead of [string!], as the datatype? If you want to contact me directly, send me your code and the DLL (I'm on W2K here), I'll see if I can figure it out. --Gregg

 [5/6] from: cyphre:seznam:cz at: 12-Jul-2002 18:14


----- Original Message ----- From: "Gregg Irwin" <[greggirwin--mindspring--com]> To: <[rebol-list--rebol--com]> Sent: Friday, July 12, 2002 5:11 PM Subject: [REBOL] Re: calling a DLL ....
> Have you tried initializing loc-data/name to a string of 41 characters,
with
> or without a null terminator, before making the call? Have you tried > [char*], instead of [string!], as the datatype? >
.... Hi Gregg, Abdel from my experience with Rebol dll interface you should also try put into the structure deffinition 41 val [char!] instead of the string! or char* like: loc-data: make struct! [ name1 [char!] name2 [char!] name3 [char!] ..... ...... name40 [char!] name41 [char!] lat [decimal!] lon [decimal!] .... ] but maybe this annoying thing was improved in the new beta release of View? anyway, here is simple function for easy generation of such structures I used some time ago: gen-chars: func [word-name num /local result][ result: copy "" insert result newline repeat n num [append result join word-name [n " [char!]" newline]] load result ] example: GFL_COLORMAP: make struct! compose/deep [ (gen-chars "Red" 256) (gen-chars "Green" 256) (gen-chars "Blue" 256) ] none good luck! regards, Cyphre

 [6/6] from: greggirwin:mindspring at: 14-Jul-2002 14:06


Hi Cyphre, << from my experience with Rebol dll interface you should also try put into the structure deffinition 41 val [char!] instead of the string! or char* like:
>>
You're actually OK using a string, in my experience, but you need to fill it with data before making the call, which "make string!" doesn't do. Since I'm not sure what REBOL does under the hood, this is based on my experience, mainly calling Windows API functions. --Gregg