LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use WinInet API to Write FTP program

I use call library function to call wininet.dll write a ftp program,but i got some problem about "ftpfindfirtfile" function,

FtpFindFirstFile
HINTERNET FtpFindFirstFile(
IN HINTERNET hFtpSession,
IN LPCSTR lpszSearchFile,
OUT LPWIN32_FIND_DATA lpFindFileData,
IN DWORD dwFlags,
IN DWORD dwContext
);

lpFindFileData
Address of a WIN32_FIND_DATA structure that receives information about the found file or directory.

typedef struct _WIN32_FIND_DATA { // wfd
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;

TCHAR cFileName[ MAX_PATH ];
TCHAR cAlternateFileName[ 14 ];
} WIN32_FIND_DATA;

i use cluster to describe WIN32_FIND_DATA structure,
but the program crashed. my program attached below.
Please give me a suggust.

Thank you.
0 Kudos
Message 1 of 7
(3,912 Views)
There are actually several issues that are probably causing the crash. First and most severe is the idea that the Adapt to Type option you are using for the structure forces you to conform to LabVIEW's memory management. LabVIEW is passing a Handle to a LabVIEW structure while the function is expecting a struct passed by value. Second, the strings inside the structure would get passed as handles to LabVIEW strings, not C String pointers as the function would require. Also, since all memory used in LabVIEW needs to be allocated by the LabVIEW memory manager, it is best to innitialize the size of any string that is going to have data put into it in external code. There may also be packing issues with the structure to contend with. Your best option for
getting this to work would be to create a wrapper function in C code for calling this function.
Message 2 of 7
(3,912 Views)
Thank for your help!
But,how to resize the strings inside the structure which be passed as handles to LabVIEW strings use the
wrapper function in c code?
0 Kudos
Message 3 of 7
(3,912 Views)
You can use the ResizeNumericArray function which is declared in the extcode.h to resize the memory associated with a LabVIEW handle. Heres an example that might help.
0 Kudos
Message 4 of 7
(3,912 Views)
You can also allot memory from within LabVIEW by just innitializing those strings to already be a sufficient size when you pass it to external code.
0 Kudos
Message 5 of 7
(3,912 Views)
Working on an FTP client in LV6 I ran in the exact same issue as Peter Pan. I came across this answer while looking for an answer to my problem.
I agree that there must be a data mismatch, but I do not agree to all what Aaron is saying.
1/ First of all, the function is expecting a pointer to the struct, what I think we're giving it. How can you else explain that functions like GetCursorPos work correctly? They also expect a pointer to the struct and what you're giving it is a "handle by value"!
2/ If the strings are passed as a "handle to Labview strings" instead of C String Pointers then we're dealing not only with a shortcoming, but also something confusing: if you send in a normal string, outside of a cluster, it defaults to C Pointer String. Ok, I gues
s because the list is alphabetically sorted?!
3/ Indeed, one has to init a "buffer string" to accept the char data. I did this, with no luck.
4/ What about the 3 embedded clusters? I could imagine LV has problems with that too...

Well, up to now I did not find a "LV only" solution. And since I don't know C or C++ I'm not able to write a wrapper. I'm trying to keep the number of external DLL's down anyway. 🐵

I'm open for a discussion, so let me know.
And to the NI gurus: the Win API is far too important to "neglect" its implementation. With plain old VB it's a snap, using very, very simple types ('clusters'), so I hope this functionally will be spoken about in new LV updates.

Thanks for your time.
Keep on smiling !

David.
0 Kudos
Message 6 of 7
(3,912 Views)
I was able to create a put, get and delete function using wininet.dll but could not get the list function to work properly. After several weeks of trying, I quit trying and decided to use an active-x FTP componet which was much easier to use. You may find such a componet at http://www.chilkatsoft.com/ChilkatFtp.asp.
0 Kudos
Message 7 of 7
(3,912 Views)