Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Works but how? 1

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
First, I must apologise if this question is a little numb but it has been puzzling me for a while. It concerns code written for a project a while ago which I am now adapting for another purpose.
I have the following code which appears in an upload program I adapted from an original by Dave Summers.

Code:
DECLARE INTEGER FtpPutFile IN wininet.DLL;
   INTEGER hConnect,;
   STRING  lpszLocalFile,;
   STRING  lpszNewRemoteFile,;
   INTEGER dwFlags,;
   INTEGER dwContext
*--------------------------------------------
   IF FtpPutFile(hftpSession, lcSource,;
         lcTarget, lnXFerType, 0) = 1
   ENDIF
If I understand correctly, the first part declares the function with variable names, the second part calls the function.
Am I right in thinking that the actual var names in the declaration are unimportant, the important thing being the name and type of var in the function itself.

Keith
 
Yes, you are right. The name of variables is unnimportant , but the type is.
You can declare the same function that way:
Code:
DECLARE INTEGER FtpPutFile IN wininet.DLL;
   INTEGER ,;
   STRING  ,;
   STRING  ,;
   INTEGER ,;
   INTEGER
and if will works again. But for the code be readable after a while I always set the name of the variables.

Borislav Borissov
 
I have wondered about that for a while.
On the same subject:-
The function returns 1 if successful and 0 if it fails?
Is there any way to tell which parameter the function failed on?

Keith
 
I am not sure if this works, but you can try:
Code:
DECLARE SetErrorMode IN "kernel32.dll" INTEGER test
DECLARE SetLastError IN "kernel32.dll" INTEGER test
DECLARE INTEGER GetLastError IN "Kernel32.dll"
DECLARE INTEGER FormatMessage IN "kernel32.dll" INTEGER flags,;
                                                    INTEGER notused,;
                                                    INTEGER error,;
                                                    INTEGER locale,;
                                                    STRING @buffer,;
                                                    INTEGER bufsize,;
                                                    INTEGER notused
DECLARE INTEGER FtpPutFile IN wininet.DLL;
   INTEGER hConnect,;
   STRING  lpszLocalFile,;
   STRING  lpszNewRemoteFile,;
   INTEGER dwFlags,;
   INTEGER dwContext

    =SetLastError(0)
    =SetErrorMode(1)


*--------------------------------------------
   IF FtpPutFile(hftpSession, lcSource,;
         lcTarget, lnXFerType, 0) = 1
   ELSE
      nLastError = GetLastError()
      cError=SPACE(255)
      FormatMessage(4096,0,nLastError,0,@cError,255,0)
      cError = ALLTRIM(STRTRAN(cError,CHR(0)))
      WAIT WINDOW 'Error # ' +ALLTRIM(STR(nLastError))+CHR(13)+'Error: '+cError
   ENDIF

Borislav Borissov
 
Thanks - I'll check it out when I have time.
I have always felt that function calling was a simple technique which the experts have shrouded in mystery.
I am beginning to think I may be right.
Could you suggest a tutorial for people like me who are not fluent in 'geek'?

Where can I buy a ball of Null Terminated String?

Keith
 
All these functions are described in MSDN library no metter what version you have, if you have. They are standart Visual C++ functions or so named WIN32API functions. If you didn't have MSDN library you can google WIN32API viewer and download some. Unfortunately all examples are writen fo VB. Other way is to subscribe to there all WIN32API functions are translated to VFP :eek:)

If you have syntax everithing is easy then (not so easy if you must deal with structures and other C++ beauty). In general:
lpsz.... means LongPointer To Zero Terminanted string - you must pass the variable by reference @myVar, etc.
You can not pass Zero terminanted strings, I think VFP doing it for you, but if you want:
myString = MyString + CHR(0)

Borislav Borissov
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top