InternetGetLastResponseInfo

G

Guest

Hi All

I'm trying to import this SDK function in C# but it fails. Here is the code I'm using

...
[DllImport("WinInet.dll", CharSet = CharSet.Auto)
private static extern bool InternetGetLastResponseInfo
[Out] int Error, [MarshalAs(UnmanagedType.LPTStr)] [Out] string sBuffer, [Out] int nBufferLengt
)
...
int nBuffLen = 0
string sBuff = null

InternetGetLastResponseInfo(nError, sBuff, nBuffLen)
sBuff = new string(' ', nBuffLen + 1)
if (InternetGetLastResponseInfo(nError, sBuff, nBuffLen)
sErrMsg += sBuff

That throws an exception (System.NullReferenceException): "Object reference not set to an instance of an object.
I did import almost all other WinInet FTP methods without any glitch

Can someone point me to the right way

Thanks
 
M

Mattias Sjögren

Emanuel,
[DllImport("WinInet.dll", CharSet = CharSet.Auto)]
private static extern bool InternetGetLastResponseInfo(
[Out] int Error, [MarshalAs(UnmanagedType.LPTStr)] [Out] string sBuffer, [Out] int nBufferLength
);

Make that

private static extern bool InternetGetLastResponseInfo(
out int Error, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder
sBuffer, ref int nBufferLength);

nBufferLength should be the size of your allocated StringBuilder
buffer on input.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top