473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

InternetGetLastResponseInfo

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
5 4518
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: MLH | last post by:
Would the following work if placed in a form module rather than a global module? Declare Sub InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long)
17
by: Lauren Wilson | last post by:
Hi folks, Can someone point me to some resources on how to control FTP sessions from and Access application with VBA? Many thanks for all help. --LW.
2
by: Emanuel | last post by:
Hi All I'm trying to import this SDK function in C# but it fails. Here is the code I'm using ... int Error, string sBuffer, int nBufferLengt ) ... int nBuffLen = 0 string sBuff = null
0
by: Sjaakie Helderhorst | last post by:
Hi all, I'm trying to create a class which handles FTP. Knowing little of classes I'm having some trouble making things work. Also having trouble finding the meaning of some error-codes. The code...
6
by: Daren Hawes | last post by:
Hi, My web host has a low security setting on the shared .net server I use. I cannot use third party dll's or install assemblies in the GAC. All I need to do is verify that a FTP login is...
17
by: Lauren Wilson | last post by:
Does anyone know if it is possible to capture FTP responses to various FTP commands when managing an FTP session from a VBA procedure? For example, if we try to login to an FTP server and the...
2
by: rdemyan via AccessMonster.com | last post by:
I currently have code that brings up a form where the user can see a list of spreadsheets on my ftp site, select one and then download and import the spreadsheet into a table. All of this...
1
by: YT | last post by:
Hi, In my C# code I call WININET's FtpPutFile function to FTP upload text files. It has a flags parameters to specify whether the transfer should be done in binary or ASCII. I've specified...
0
by: douglandmesser | last post by:
Hey all. I found this awesome source code online that covers basically all of the wininet.dll function calls for FTP commands. It doesn't, however, actually work! lol The code is below: Source -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.