WinInet DECLS to Mod - But Wrong
BlitzMax Forums/BlitzMax Programming/WinInet DECLS to Mod - But Wrong
| ||
Hi, This works in B3d : DECLS : .lib "wininet.dll" InternetOpen%(Agent$, AccessType%, ProxyName%, ProxyBypass%, Flags%):"InternetOpenA" CODE : H=InternetOpen("...",0,0,0,0) But this doesn't work in BMax : MOD: Extern Function InternetOpenA:Int(lpszAgent:String,dwAccessType:Int,lpszProxyName:Int,lpszProxyBypass:Int,dwFlags:Int) = "InternetOpenA@20" End Extern CODE: Local H:Int=InternetOpenA("...",0,0,0,0) Now I have no idea why the B3D version works, because the MSDN says everything is supposed to be a pointer, but it does work just fine. Try it. The BMax version gives a value which changes constantly ( I have no idea why ) and then causes an unhandled memory exception error when the program finishes. Now possibly I'm going blind, but to me, it's the same damn code. EDIT: To clarify, it works as long as you only touch the variable you put it in once. If you debuglog H over and over, that's when it goes wrong. If you do the same thing in B3d, it's fine. EDIT 2: If you make H a Global instead of a Local, it stops changing value. WHY!? It still has the unhandled memory exception error though. EDIT 3: If you change everything to what the MSDN asks for ( IE: Pointers to strings ) then it works without any errors. EXCEPT that you then can't put it into a function, because if you do, it goes back to throwing an unhandled memory exception error. This is just ridiculous. |
| ||
.Nevermind, it crashes too. I'll keep trying Btw, are you trying to read a file off the net or something? I Might be able to help with other methods |
| ||
Extern "Win32"?? |
| ||
shouldn't lpsz be a Byte Ptr? |
| ||
Here's how I tried it:Import "-lwininet" Extern Function InternetOpen(sAgent:Byte Ptr, lAccessType, sProxyName:Byte Ptr, sProxyBypass:Byte Ptr, lFlags) = "InternetOpenA@20" End Extern Local hOpen = InternetOpen("test", 1, "", "", 0) DebugLog hOpen DebugLog hOpen DebugLog hOpenbut this causes an odd crash: 13369348 2009443488 2009443488 Assertion failed: scopeStackTop>0, file C:/Program Files/BlitzMax/mod/brl.mod/appstub.mod/debugger.stdio.c, line 487 This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Unhandled Exception: Received Signal BlitzMax Console Debugger H=HelpDeclare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long |
| ||
Wouldn't it be something like...Import "-lwininet" Extern "Win32" Function InternetOpen(sAgent$z, lAccessType, sProxyName$z, sProxyBypass$z, lFlags) = "InternetOpenA@20" End Extern Local hOpen = InternetOpen("test", 1, Null, Null, 0) DebugLog Hex(hOpen) DebugLog Hex(hOpen) DebugLog Hex(hOpen) DebugLog "" test() End Function test() Local hOpen = InternetOpen("test1", 1, Null, Null, 0) DebugLog Hex(hOpen) DebugLog Hex(hOpen) DebugLog Hex(hOpen) End Function?? |
| ||
shouldn't lpsz be a Byte Ptr? I thought so, but as I said, doesn't work that way either. As soon as it goes in a function or in a local variable, that crashes too. Extern "Win32" Just a little hangover I had from trying everything I could think of. It was like that most of the time and it doesn't make any difference. Yet going back now and making that change has it working just fine, lmao. And I know I tried that about five times without it working last night. I must be losing the plot. Crikey Eikon, that's almost the same way I did it with Byte Ptr's and a new and weirder error. The only difference was that I used ToCString on the strings. Melvin: Although just the Win32 bit seems to make it work now, that last way looks good as it saves the ToCString bit by using the $z. Is any cleanup needed with $z now that the garbage collector is automatic? EDIT: Having checked another question about ToCString's I had last night, I now know that the answer is no, Max cleans up after $z's. Thanks to everyone for all the help. |
| ||
No clean up needed with $z. :o) |