i have this i need converted to asm:
RASCONN * lpRasConn;

DWORD lpcb;
DWORD lpcConnections;

lpRasConn = (LPRASCONN) GlobalAlloc(GPTR, sizeof(RASCONN));
lpRasConn->dwSize = sizeof(RASCONN);
lpcb = sizeof(RASCONN);

nRet = RasEnumConnections(lpRasConn, &lpcb, &lpcConnections);
if (nRet != 0)
{
printf("RasEnumConnections failed: Error = %d", nRet);
}
else
{
printf("The following RAS connections are currently active\n\n");
for (i = 0; i < lpcConnections; i++)
{
printf("Entry name: %s\n", lpRasConn->szEntryName);
lpRasConn++;
}
}


i converted it to this:
.data?

ras1 RASCONN <>
ras3 DWORD ?

.code
start:

invoke GlobalAlloc,GPTR, sizeof RASCONN
mov ras1.dwSize,eax
invoke RasEnumConnections,addr ras1,sizeof RASCONN,addr ras3
.if eax == 0
invoke MessageBox,0,0,0,0
.endif

invoke ExitProcess,NULL
end start

on success the RasEnumConnections is suppose to return a 0 and i dont get it so im assuming i made an error in the conversion.
Posted on 2002-02-17 12:17:51 by smurf
Smurf,

If the API wants a pointer, give it a pointer...

nRet = RasEnumConnections(lpRasConn, &lpcb, &lpcConnections);
lpcb

Points to a variable that contains the size, in bytes, of the buffer specified by lprasconn. On return, the function sets this variable to the number of bytes required to enumerate the RAS connections.


If you just give it a number (sizeoff ...), the api will treat that as a pointer, NOT A NUMBER (heheh get it NaN)

Do what the source has done by declairing a dummy variable (lpcb) and set that variable to the size as well, and in the api, give it that address....

I didnt check it, but this *should* get things working..
:alright:
NaN
Posted on 2002-02-17 12:28:55 by NaN
Man, on a second look over, there is other mistakes...

First, the C++ version doesnt declair an entire structure at the begining.. it declairs only a pointer. (DWORD LENGHT)

RASCONN * lpRasConn; <-- this is DWORD!

The global alloc then *creates* enought memory to be filled as described by the STUCT template. When created it returns the POINTER to the area of memory, which is conveniently stored in the variable-pointer (lpRasConn), described to be regulated by the same stucture (RASCONN).

However, your attempt first allocates this space in the .data? section. So the need for the global alloc is now redundant, as you already have this space provided!

All corrections discussed then would make your code to be:


.data?
ras1 RASCONN <>
[b]lpRas3[/b] DWORD ? ; since it will return a pointer (note it!)
[b]dummy DWORD ?[/b]

.code
start:

[b]; FORGET THIS invoke GlobalAlloc,GPTR, sizeof RASCONN[/b]
[b]; THIS TOO! mov ras1.dwSize,eax (EAX != SIZE!)[/b]
[b]; ADD THE FOLLOWING:

mov ras1.dwSize, SIZEOF RASCONN
mov dummy, SIZEOF RASCONN

[/b]invoke RasEnumConnections,addr ras1,[b]ADDR dummy[/b],addr [b]lpRas3[/b]
.if eax == 0
invoke MessageBox,0,0,0,0
.endif

invoke ExitProcess,NULL
end start


If you read the API reference you will see that the DUMMY variable will have some "meaning" or value upon the api working ok.. you should read up on it and see how important this returned info (in dummy) is to your needs.

Enjoy..
:alright:
NaN
Posted on 2002-02-17 12:50:22 by NaN
hmm.. i assembled the code in your last post and it appears that the function isnt working. i wonder what the heck is going on. maybe it has to do with something on my computer. im networked and i share the modem with another computer.
Posted on 2002-02-17 13:02:06 by smurf
Well im networkin illiterate, and have no modem, and only one machine on "my" network ~~ So i get a 610 Error when i try it (dunno what it means, the headers dont have the error code in them), but here is my full transcription of the posted C++ version:



[b].data[/b]
szFormatFail BYTE "Ras EnumConnections failed: Error %d",13,10,0
szFormatGood BYTE "Entry name: %s\n, lpRasConn->szEntryName)",13,10,0

[b].data?[/b]
OutBuffer BYTE 128 dup(?)
Counter DWORD ?


lpRasConn DWORD ?
lpcb DWORD ?
lpcConnections DWORD ?


[b].code[/b]
start:

invoke GlobalAlloc, GPTR, SIZEOF RASCONN
mov lpRasConn, eax

mov edx, lpRasConn
mov (RASCONN PTR [edx]).dwSize, SIZEOF RASCONN
mov lpcb, SIZEOF RASCONN

invoke RasEnumConnections, lpRasConn, addr lpcb, addr lpcConnections
.if( eax != 0 )
invoke wsprintf, addr OutBuffer, addr szFormatFail, eax
invoke MessageBox, NULL, addr OutBuffer, NULL, NULL
.else
mov Counter, 0
mov eax, Counter
.while( eax < lpcConnections )

mov edx, lpRasConn
lea eax, (RASCONN PTR [edx]).szEntryName
invoke wsprintf, addr OutBuffer, addr szFormatGood, eax
invoke MessageBox, NULL, addr OutBuffer, NULL, NULL
add lpRasConn, SIZEOF RASCONN

inc Counter
mov eax, Counter
.endw

.endif
invoke GlobalFree, lpRasConn
call ExitProcess
[b]end start[/b]


One of the intersting things I see, is that the C version defines only 1*RASCONN bytes of memory, and fills the dsSize entry accordingly. Then when you pass this to the API, it *should* return an ARRAY of RASCONN's ie) X * RASCONN, where X is # of entries. So im assuming that global mem pointer is being free'd by the API, then a new one is put in the old pointer's place, befor returning. The API doc's dont say too much how this actually works?? But i wrote my code to follow suite (as the C version does).

Aslo, on last posibility is that the structure itself is mis-translated. I noted in the API reference that the reason you are to define just on RASCONN in the first place is to give the API an indication of which *version* your using. If the translation here is miss represented, this could cause the persistant error.

Hope it helps...
:alright:
NaN
Posted on 2002-02-17 13:53:01 by NaN
This is what Windows.inc has:

RASCONNA STRUCT

dwSize dd ?
hrasconn dd ?
szEntryName db RAS_MaxEntryName + 1 dup(?)
szDeviceType db RAS_MaxDeviceType + 1 dup(?)
szDeviceName db RAS_MaxDeviceName + 1 dup(?)
RASCONNA ENDS


And this is what the C++ definition is:
RASCONNA

{
DWORD dwSize;
HRASCONN hrasconn;
CHAR szEntryName[ RAS_MaxEntryName + 1 ];

#if (WINVER >= 0x400)
CHAR szDeviceType[ RAS_MaxDeviceType + 1 ];
CHAR szDeviceName[ RAS_MaxDeviceName + 1 ];
#endif
#if (WINVER >= 0x401)
CHAR szPhonebook [ MAX_PATH ];
DWORD dwSubEntry;
#endif
};


So as you can see this *might* be a source of probs. I still cant verify (for above reasons), but i tried the 3 possibilities, and all 3 give me the same error (probably == No Modem).

BTW: The defined ASM version assumes WINVER == 0x400

Good Luck... i've done all that i can..
:alright:
NaN
Posted on 2002-02-17 14:12:47 by NaN
nan i also got an error but it wasnt the same one you got. i get an error 632.:confused: anyways thank you helping you've cleared alot up for me.
Posted on 2002-02-17 18:46:10 by smurf