By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,667 Members | 1,697 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,667 IT Pros & Developers. It's quick & easy.

InternetGetLastResponseInfo

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.
Nov 15 '05 #2

P: n/a
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 intlpdwError, StringBuilder lpszBuffer, ref int lpdwBufferLength );
Mattias

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

Nov 15 '05 #3

P: n/a
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.
.

.

Nov 15 '05 #4

P: n/a
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
-----Original Message-----
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


Nov 15 '05 #5

P: n/a
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.