Thread: API, LOST... help

  1. #1
    Unregistered
    Guest

    API, LOST... help

    I am so confused.
    Im trying to get the hang of win 32 api but im lost so far.
    take this for example.


    BOOL GetComputerName(
    LPTSTR lpBuffer, // computer name
    LPDWORD lpnSize // size of name buffer
    );

    BOOL I know returns true or false (1,0)
    But what do I declare lpBuffer and lpnSize with ?

    I see alot of API using these unknown(to me) data types.

    Do I just LPTSTR mybuf[20];
    and LPDWORD max = 21; ?????

    Really lost, please help me get the hang of this.

    Thanks

  2. #2
    Unregistered
    Guest
    And something simple like this isnt even working.
    BOOL LockWorkStation(VOID);


    #include <stdio.h>
    #include <windows.h>
    #include <winuser.h>


    int main() {

    LockWorkStation();
    return 0;

    }


    This errors and says


    C:\crap\test.cpp(10) : error C2065: 'LockWorkStation' : undeclared identifier

    Any one ?

  3. #3
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    I'm not sure about LockWorkStation...I think it's one of those things you can't use on Win9x, so if you're compiling on a 9x platform it won't work anyway...


    With GetComputerName() it's quite simple...

    char compName[20];
    GetComputerName(name, 20);


    LPTSTR = Long Pointer To a String (If I'm not mistaken); most of the time you can just use a char* here.
    LPDWORD = Long Pointer to a DWORD. DWORD is a double-word, but you can just use an int....

  4. #4
    Unregistered
    Guest
    #include <stdio.h>
    #include <windows.h>

    int main()

    {

    char cname[20];
    GetComputerName(cname,20);
    printf("Computer name = %s\n",cname);

    return 0;
    }

    Error:

    C:\crap\test.cpp(9) : error C2664: 'GetComputerNameA' : cannot convert parameter 2 from 'const int' to 'unsigned long *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe.

    And for lockworkstation im running 2k (NT) so it should work.

  5. #5
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    so type cast, my man.

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    BOOL GetComputerName
    (
    LPTSTR lpBuffer, // computer name
    LPDWORD lpnSize // size of name buffer
    );

    int main()
    {
    TCHAR cBuffer[50];
    DWORD dwSize = 50;

    if( GetComputerName( cBuffer, &dwSize ) )
    {
    printf( "%s %d\n", cBuffer, dwSize );
    }
    else
    {
    printf( "Error" );
    }

    return 0;
    }



    LPSTR is char*
    LPTSTR is TCHAR*
    LPCTSTR is const TCHAR*
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Want to learn Windows API for Game Programming
    By George M. in forum Windows Programming
    Replies: 15
    Last Post: 09-28-2008, 10:26 AM
  2. platform specific API or C standard API
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 01:32 AM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  4. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  5. Is it foolish to program with Win32 API ?
    By Kelvin in forum Windows Programming
    Replies: 2
    Last Post: 07-09-2002, 02:03 PM