Command Line compiling API and MFC programs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dr. Laurence Leff

    #1

    Command Line compiling API and MFC programs

    How does not compile a Windows API and a Windows MFC program from the
    command line with Visual.net. (I can do the former, at least, with Visual
    Studio by creating a "Win32 Project.")

    However, I tried the same thing on the command line.
    (In the days of Visual C++ 4.0 through Visual C++ 6.0, I had some
    make files and stuff that did this.

    So, I typed CL hellowin.C

    There were no compile time erors; only errors from the linker
    such as error LNK2019: unreasolved external symbol
    ___imp__Dispatc hMessageA4

    I got similar errors from other basic Windows API functions such
    as Show Window, DrawText and BeginPaint.

    So I believe that I need to know what libraries are needed and how to
    specify these. The "CL" command does not accept the "/LIBRARY" option
    from Visual C++ 4.0

    Thanks for any help that can be provided.


    Dr. Laurence Leff Western Illinois University, Macomb IL 61455 ||(309) 298-1315
    Stipes 447 Assoc. Prof. of Computer Sci. Pager: 309-367-0787 FAX: 309-298-2302
    Secretary: eContracts Technical Committee OASIS Legal XML Member Section

    Here is the helowin.c file:


    #include "c:\progra~1\mi cros~1.net\Vc7\ PlatformSDK\Inc lude\Windows.h"
    #include "stdio.h"

    int count;
    HINSTANCE ghInstance;

    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

    int WINAPI WinMain (HINSTANCE hInstance,
    HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int iCmdShow)

    {
    HWND hWnd;
    MSG msg;
    WNDCLASSEX wndclass;
    static char szAppName[] = "HelloWin";
    ghInstance = hInstance;

    wndclass.cbSize = sizeof (wndclass);
    wndclass.style= CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWn dProc = WndProc;
    wndclass.cbClsE xtra = 0;
    wndclass.cbWndE xtra = 0;
    wndclass.hInsta nce = hInstance;
    wndclass.hIcon = LoadIcon (hInstance,IDI_ APPLICATION);
    wndclass.hCurso r = LoadCursor (NULL, IDC_ARROW);
    wndclass.hbrBac kground = (HBRUSH) GetStockObject (WHITE_BRUSH);
    wndclass.lpszMe nuName =NULL;
    wndclass.lpszCl assName =szAppName;
    wndclass.hIconS m = LoadIcon (NULL,IDI_APPLI CATION);

    RegisterClassEx (&wndclass);

    hWnd = CreateWindow (
    szAppName,
    "The Hello Program",
    WS_OVERLAPPEDWI NDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    NULL,
    NULL,
    hInstance,
    NULL);

    ShowWindow (hWnd, iCmdShow);
    UpdateWindow (hWnd);


    while (GetMessage(&ms g,NULL,0,0))
    {
    TranslateMessag e(&msg);
    DispatchMessage (&msg);
    }
    return msg.wParam;

    }

    LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
    {
    HDC hDC;
    PAINTSTRUCT ps;
    RECT rect;
    char str[100];
    switch (iMessage)
    {
    case WM_CREATE:
    return 0;
    count = 0;
    case WM_PAINT:
    hDC = BeginPaint (hWnd, &ps);
    GetClientRect (hWnd,&rect);
    sprintf(str,"%d ",count);
    DrawText (hDC, str, -1, &rect,
    DT_SINGLELINE | DT_CENTER | DT_VCENTER);
    EndPaint (hWnd, &ps);
    return 0;
    case WM_LBUTTONDOWN:
    count++;
    InvalidateRect( hWnd,NULL,TRUE) ;
    return 0;
    case WM_DESTROY:
    PostQuitMessage (0);
    break;
    default:
    return DefWindowProc (hWnd, iMessage, wParam, lParam);
    }
    return (0L);
    }
  • jacob navia

    #2
    Re: Command Line compiling API and MFC programs

    Dr. Laurence Leff wrote:
    [snip][color=blue]
    > So I believe that I need to know what libraries are[/color]
    [snip]

    Yes. You have to tell the compiler the libraries you need.

    If you read your compiler documentation, you will find the
    name.

    It is better when starting, to use the IDE provided by Microsoft
    because it gives access to the documentation. For each function
    the doc tells you which library is needed.

    Besides, it shields the novice programmer from many complexities.

    Load your program in the editor, and type F1 at the name
    you want to investigate. Then, if the installation went OK,
    the help system will display you the doc of that function.

    I would ask further questions in the many support groups of the
    compiler in the net.

    jacob



    Comment

    • Flash Gordon

      #3
      Re: Command Line compiling API and MFC programs

      Dr. Laurence Leff wrote:[color=blue]
      > How does not compile a Windows API and a Windows MFC program from the
      > command line with Visual.net. (I can do the former, at least, with Visual
      > Studio by creating a "Win32 Project.")[/color]

      <snip>

      This is all very Windows MSVC specific and thus off topic in
      comp.lang.c, it belongs somewhere in one of the MS specific news groups.
      --
      Flash Gordon
      Living in interesting times.
      Although my email address says spam, it is real and I read it.

      Comment

      Working...