Parameter zuweis
-
This function returns a pointer to the command-line string for the current process.
LPTSTR GetCommandLine(void);
Parameters
None.Return Values
The return value is a pointer to the command-line string for the current process.So habe ich es in der MSDN gefunden.Aber ich möchte jetz zwar nich blöd rüberkommen aber wich frage ich den Reutrn ab?
-
Aber ich möchte jetz zwar nich blöd rüberkommen aber wich frage ich den Reutrn ab?
Zu spät...
Die Frage ist nicht ernst gemeint oder ???
MfG veganza
-
Zu spät
soory muste ich bis jetz bei sowas noch nich machen
-
Wie ruft Du ansonsten Funktionen auf, deren Rückgabewert du auswerten willst ???
Das hat doch nichts mit GetCommandLine() o.ä. zu tun, das ist ein stink-normaler Funktionsaufruf wie z.B. AfxMessageBox() nur das bei GetCommandLine() kein int sondern ein LPTSTR zurückgegeben wird.Wenn Du schon mal vorher C/C++ programmiert hast, dann solltest Du wissen, wie man Funktionen aufruft
MfG veganza
-
Das läuft ganz einfach:
typ Rückgabewert = Funktion( parameter1, parameter 2, ... );
In diesem Fall:
LPTSTR *szString = GetCommandLine();
So, und nun üben wir dies an einem einfachen Win32-API-Beispiel:
#define WIN32_LEAN_AND_MEAN #include <windows.h> int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { char* szString = GetCommandLine(); MessageBox(NULL, szString, "", MB_OK); MessageBox(NULL, lpCmdLine, "", MB_OK); return 0; }
Wie Du siehst, bringt das char* lpCmdLine genau die übergebenen Parameter, die Du suchst. Aus unserem szString muß man das noch "herausschneiden".
[ Dieser Beitrag wurde am 06.10.2002 um 00:00 Uhr von Erhard Henkes editiert. ]
-
Wichtig ist auch folgender Hinweis aus MSDN bezüglich ANSI und Unicode:
ANSI console processes written in C can use the argc and argv arguments of the main function to access the command-line arguments.
ANSI GUI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name.
The reason that main and WinMain cannot return Unicode strings is that argc, argv, and lpCmdLine use the LPSTR data type for parameters, not the LPTSTR data type. The GetCommandLine function can be used to access Unicode strings, because it uses the LPTSTR data type.
-
@Erhard:
Muss es stattLPTSTR *szString = GetCommandLine();
nicht
LPTSTR szString = GetCommandLine();
heissen ?
LPTSTR ist ja schon ein Zeiger: Large Pointer To [a] STRing[ Dieser Beitrag wurde am 06.10.2002 um 01:27 Uhr von dEUs editiert. ]
-
@dEUs: Danke für den Korrekturhinweis. LPTSTR ist schon ein Zeiger.
Das T steht jedoch für Unicode nicht für "to". Das ist alles irgendwie kompliziert:
LPSTR: Pointer to a null-terminated string of 8-bit Windows (ANSI) characters.
LPWSTR: Pointer to a null-terminated string of 16-bit Unicode characters.
LPTSTR: An LPWSTR if UNICODE is defined, an LPSTR otherwise.ist analog zu:
CHAR: 8-bit Windows (ANSI) character.
WCHAR: 16-bit Unicode character.
TCHAR: A WCHAR if UNICODE is defined, a CHAR otherwise.aus Charles Petzold's Windows Programming:
So far, we have the data types CHAR (which is an 8-bit char) and WCHAR (which is a 16-bit wchar_t) and pointers to CHAR and WCHAR. As in TCHAR.H, WINNT.H defines TCHAR to be the generic character type. If the identifier UNICODE (without the underscore) is defined, TCHAR and pointers to TCHAR are defined based on WCHAR and pointers to WCHAR; if the identifier UNICODE is not defined, TCHAR and pointers to TCHAR are defined based on char and pointers to char:#ifdef UNICODE typedef WCHAR TCHAR, * PTCHAR ; typedef LPWSTR LPTCH, PTCH, PTSTR, LPTSTR ; typedef LPCWSTR LPCTSTR ; #else typedef char TCHAR, * PTCHAR ; typedef LPSTR LPTCH, PTCH, PTSTR, LPTSTR ; typedef LPCSTR LPCTSTR ; #endif
Woher das T abkürzungstechnisch herkommt, weiß ich leider auch nicht genau.
Kennt jemand den genauen Hintergrund?
-
Das T steht in PTSTR (bzw. LPTSTR) also für TCHAR. (Das L für long stammt noch aus der 16-bit-Zeit und kann heute entfallen.) Somit sollte TCHAR.h der Schlüssel zu T sein. Dort findet sich allerdings keine genaue Zuordnung. Es wird immer nur von "generic text mapping" gesprochen. Vielleicht kommt das T von Text. _T(...) ist ja auch identisch zu TEXT(...).
-
TCHAR bedeutet text character.
LPTSTR bedeutet nun also "long pointer to text character string".