Page 1 of 1

Convertion VC++ -> PureBasic

Posted: Fri May 16, 2003 7:20 pm
by Phlos
Salut,

J'ai besoin d'aide. Il faut que je convertisse ce code en Pure Basic, mais je sais pas du tout le faire. C'est une sorte de structure (ou tableau je ne sais pas) dont le pointeur est renvoyé par la fonction "GetMyAPIInfo".

Je précise que la fonction "GetMyAPIInfo" est une fonction dans une dll :)

Merci d'avance.


--------------------------------------------------------------------
IN ENGLISH:

Hello,

I need help. I need to make a convertion of this code to Pure Basic, but i dont know how to do this. It is a structure (or an array, i dont know...lol).

The function "GetMyAPIInfo" is a function of a DLL :)

Thanks.


Code: Select all

typedef struct
{
	char *module_name;
	char *function_name;
	char *myfunc_name;
}MYAPIINFO;

MYAPIINFO myapi_info[] =
{
	{"WSOCK32.DLL", "socket(a, b, c)", "mysocket"},
	{"WSOCK32.DLL", "closesocket(a)", "myclosesocket"},
	{NULL,NULL,NULL}
};

MYAPIINFO *GetMyAPIInfo()
{
	return &myapi_info[0];
}

Posted: Fri May 16, 2003 10:05 pm
by ebs
Phlos,

Here is my translation:

Code: Select all

Structure MYAPIINFO
  module_name.l
  function_name.l
  myfunc_name.l
EndStructure

Dim myapi_info.MYAPIINFO(3)

myapi_info(0)\module_name = @"WSOCK32.DLL"
myapi_info(0)\function_name = @"socket(a, b, c)"
myapi_info(0)\myfunc_name = @"mysocket"

myapi_info(1)\module_name = @"WSOCK32.DLL"
myapi_info(1)\function_name = @"closesocket(a)"
myapi_info(1)\myfunc_name = @"myclosesocket"

myapi_info(2)\module_name = 0
myapi_info(2)\function_name = 0
myapi_info(2)\myfunc_name = 0

Procedure.l GetMyAPIInfo()
  ProcedureReturn @myapi_info(0)
EndProcedure

; just to be sure its all there!
Debug PeekS(myapi_info(0)\module_name)
Debug PeekS(myapi_info(0)\function_name)
Debug PeekS(myapi_info(0)\myfunc_name)

Debug PeekS(myapi_info(1)\module_name)
Debug PeekS(myapi_info(1)\function_name)
Debug PeekS(myapi_info(1)\myfunc_name)

Debug GetMyAPIInfo()
Debug PeekS(PeekL(GetMyAPIInfo()))
If anyone can find errors, please post them.

Regards,
Eric

Posted: Fri May 16, 2003 10:18 pm
by dmoc
Excuse me Eric if I'm wrong, can't check at the mo:

I think these are pointers anyway?

Code: Select all

Structure MYAPIINFO 
  module_name.s
  function_name.s 
  myfunc_name.s
EndStructure
So...

Code: Select all

myapi_info(0)\module_name = "WSOCK32.DLL" 
myapi_info(0)\function_name = "socket(a, b, c)" 
myapi_info(0)\myfunc_name = "mysocket" 

myapi_info(1)\module_name = "WSOCK32.DLL" 
myapi_info(1)\function_name = "closesocket(a)" 
myapi_info(1)\myfunc_name = "myclosesocket" 

myapi_info(2)\module_name = 0 
myapi_info(2)\function_name = 0 
myapi_info(2)\myfunc_name = 0 
...
Procedure.l GetMyAPIInfo() 
  ProcedureReturn @myapi_info(0)\module_name
EndProcedure
...and if that doesn't work do this...

Code: Select all

Structure MYAPIINFO
  dummy.l
  module_name.s
  function_name.s 
  myfunc_name.s
EndStructure
...
Procedure.l GetMyAPIInfo() 
  ProcedureReturn @myapi_info(0)\dummy+4
EndProcedure
PS: "Dummy" may refer to me, it's been a long day :?

Posted: Fri May 16, 2003 10:27 pm
by ebs
dmoc,

That was my first attempt. It will work when you assign strings (array elements 0 and 1), but you'll get an error when you try to assign a number (0) to a string variable (array element 2):

Code: Select all

; this is OK
myapi_info(0)\module_name = "WSOCK32.DLL"
myapi_info(0)\function_name = "socket(a, b, c)"
myapi_info(0)\myfunc_name = "mysocket"

; so is this
myapi_info(1)\module_name = "WSOCK32.DLL"
myapi_info(1)\function_name = "closesocket(a)"
myapi_info(1)\myfunc_name = "myclosesocket"

; this gives an error
myapi_info(2)\module_name = 0
myapi_info(2)\function_name = 0
myapi_info(2)\myfunc_name = 0
That's why I went with long variables instead of strings. If there is a way to assign a NULL string (not an empty string ""), then I think using the string variables is the better way to go. Do you know how?

Eric

Posted: Fri May 16, 2003 11:01 pm
by Phlos
Thanks a lot guys, but after debugging the right code is here :

Code: Select all

Structure MYAPIINFO 
  module_name.s
  function_name.s 
  myfunc_name.s
EndStructure 

Dim myapi_info .MYAPIINFO(3) 

myapi_info(0)\module_name = "WSOCK32.DLL" 
myapi_info(0)\function_name = "socket(a, b, c)" 
myapi_info(0)\myfunc_name = "mysocket" 

myapi_info(1)\module_name = "WSOCK32.DLL" 
myapi_info(1)\function_name = "closesocket(a)" 
myapi_info(1)\myfunc_name = "myclosesocket" 

Procedure GetMyAPIInfo() 
  ProcedureReturn myapi_info()
EndProcedure 
Other question : Can we use a list of strings like C++ ? I mean for example :

Code: Select all

 myapi_info(0) = "WSOCK32.DLL",  "socket(a, b, c)",  "mysocket" 
Because it is boring to do :

Code: Select all

myapi_info(0)\module_name = "WSOCK32.DLL" 
myapi_info(0)\function_name = "socket(a, b, c)" 
myapi_info(0)\myfunc_name = "mysocket" 

Posted: Fri May 16, 2003 11:13 pm
by dmoc
Can we use a list of strings like...
We wish! You could read it in as data (see the manual for details) but it's still not as convenient.

Null? I supose for Phlos's purpose it's now academic (and maybe best avoided anyway?) but there is #NULL defined, but as zero, so that's no use. Try this and see if you can make any sense of it :roll:

Code: Select all

a.s
b.s = ""
Debug (a = b)
End

Posted: Fri May 16, 2003 11:17 pm
by dmoc
Ha! Just had an idea...

PokeS(@myapi_info(0), "WSOCK32.DLL"+chr(0)+"socket(a, b, c)"+chr(0)+"mysocket")

Maybe have to frigg about with the @myapi_info(0)

On second thoughts... what a crap idea! Time for bed... See ya!

Posted: Sat May 17, 2003 8:56 am
by Phlos
Thanks. 8)