InternetGetLastResponseInfo

R

Rudolf

Does someone have a working sample of using the
InternetGetLastResponseInfo API call from C#?

It seems the parameters or declarations I'm using does not
work or cause a System.ExecutionEngineException exception
that even though there is a try catch for it bombs the
code out.

The last attempt declared it like:

[DllImport("wininet.dll")]
private static extern bool InternetGetLastResponseInfo
(out int lpdwError, out string lpszBuffer, ref int
lpdwBufferLength );

And I try to use it like :

bool bRet;
int iError = 0;
string sError = new string('\0', 1024);
int iBuffer = 1024;
bRet = InternetGetLastResponseInfo( out iError, out
sError, ref iBuffer);

And get:
An unhandled exception of
type 'System.ExecutionEngineException' occurred...

Thanks

Rudolf
 
M

Mattias Sjögren

Rudolf,
[DllImport("wininet.dll")]
private static extern bool InternetGetLastResponseInfo
(out int lpdwError, out string lpszBuffer, ref int
lpdwBufferLength );

Make that

[DllImport("wininet.dll", CharSet=CharSet.Auto)]
private static extern bool InternetGetLastResponseInfo(out int
lpdwError, StringBuilder lpszBuffer, ref int lpdwBufferLength );



Mattias
 
R

Rudolf

Thanks! Work like a charm.

Rudolf

Learning something new every day.
-----Original Message-----
Rudolf,
[DllImport("wininet.dll")]
private static extern bool InternetGetLastResponseInfo
(out int lpdwError, out string lpszBuffer, ref int
lpdwBufferLength );

Make that

[DllImport("wininet.dll", CharSet=CharSet.Auto)]
private static extern bool InternetGetLastResponseInfo (out int
lpdwError, StringBuilder lpszBuffer, ref int lpdwBufferLength );



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.
 
R

Rudolf

Sorry, another related question, what should the
declaration of

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct WIN32_FIND_DATA
{
public uint fileAttributes;
public fFILETIME creationTime;
public fFILETIME lastAccessTime;
public fFILETIME lastWriteTime;
public uint fileSizeHigh;
public uint fileSizeLow;
public uint reserved0;
public uint reserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
public string fileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=14)]
public string alternateFileName;
}

static extern int FtpFindFirstFile (int hFtpSession,
string lpszSearchFile, out WIN32_FIND_DATA lpFindFileData,
int dwFlags, int dwContent);

be for the WIN32_FIND_DATA structure to return the
filename property? I'm just getting nulls in the field
even though I tried initializing it before.

Thanks

Rudolf

-----Original Message-----
Thanks! Work like a charm.

Rudolf

Learning something new every day.
-----Original Message-----
Rudolf,
[DllImport("wininet.dll")]
private static extern bool InternetGetLastResponseInfo
(out int lpdwError, out string lpszBuffer, ref int
lpdwBufferLength );

Make that

[DllImport("wininet.dll", CharSet=CharSet.Auto)]
private static extern bool InternetGetLastResponseInfo (out int
lpdwError, StringBuilder lpszBuffer, ref int lpdwBufferLength );



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.
.
 
R

Rudolf

This time I solved my problem myself. It seems the
FtpFindFirstFile API always returns ANSI but dotnet
automatically defaults to unicode when
CharSet=CharSet.Auto.

The declaration should thus be:

[StructLayout(LayoutKind.Sequential,
CharSet=CharSet.Ansi)]
public struct WIN32_FIND_DATA
{
public uint fileAttributes;
public fFILETIME creationTime;
public fFILETIME lastAccessTime;
public fFILETIME lastWriteTime;
public uint fileSizeHigh;
public uint fileSizeLow;
public uint reserved0;
public uint reserved1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
public string fileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=14)]
public string alternateFileName;
}

[DllImport("wininet.dll")]
static extern int FtpFindFirstFile (int hFtpSession,
string lpszSearchFile, out WIN32_FIND_DATA lpFindFileData,
int dwFlags, int dwContent);

Rudolf
 
M

Mattias Sjögren

Rudolf,
This time I solved my problem myself. It seems the
FtpFindFirstFile API always returns ANSI

That's because you're calling the ANSI version of the function
(FtpFindFirstFileA). There's also a Unicode version FtpFindFirstFileW,
and if you include CharSet=CharSet.Auto in the DllImport attribute the
runtime will pick the best one for you.

but dotnet
automatically defaults to unicode when
CharSet=CharSet.Auto.

Actually, with Auto it uses what's best for the platform, which is
Unicode on Win NT/2000/XP/2003 and ANSI on Win 9x/ME.



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