Results 1 to 7 of 7

Thread: Small Apps

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Question Small Apps

    I was able to create a 16kb basic application with the tips here:
    http://www.mvps.org/user32/nocrt.html

    This poses a couple of problems.
    Since all the default libraries are being ignored, using math.h or any other header (have not tested) then the linker complains trying to use a function from the library. The attached project uses sinf(float) from math.h but it will not link. I am not sure if you have to link to another library file and what it is called if so (not math.lib).

    Secondly, I have no idea how to write an operator function for 'using' and 'namespace' . Adding #include<sstream> and using namespace std; will not link.

    Any ideas?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Use CRT. Ignoring it only makes sense if you rely completly on the WinAPI functions.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    I revived this thread because I have been able to compile the following code down to 16kb from the default 36kb in VC++ release build.

    Make sure "Ignore all default libraries" is checked and you add msvcrt.lib, kernel32.lib, and user32.lib to link.
    Code:
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
    
    	MessageBox(0, "Hello, World!", "Hello", 0);
    
    	return 0;
    }
    Now this code won't link unless you include msvcprt.lib in the link.
    Code:
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    #include <string>
    
    using namespace std;
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
    
    	string str = "Hello, World!";
    
    	MessageBox(0, str.c_str(), "Hello", 0);
    
    	return 0;
    }
    This code won't link because I don't know the .lib(s)
    Code:
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    #include <sstream>
    
    using namespace std;
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
    
    	ostringstream oss;
    
    	return 0;
    }
    Now, my question is, what are the other libraries for the rest of the STL?

    I at least need the .lib for <iostream> and <sstream> since I use these quite often.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Source Code.
    Attached Files Attached Files

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    All of the STL should be in the compiler-specific version of msvcprt.lib. I'm not sure if VC7 uses another name for it (it does for the dll).

    It should be possible to reduce the size even more by just doing this:
    Code:
    int __stdcall MessageBoxA(void* hWnd, const char *szText, const char *szCaption, unsigned long flags);
    
    void Entry()
    {
      MessageBoxA((void*)0, "", "", 0);
    }
    Put it in a .c file, not .cpp. In the linker settings you must set the entry point to Entry and the ONLY lib to include is user32.lib
    0 is the value of MB_OK.

    Maybe this call would require even less space:
    Code:
    void Entry()
    {
      long l = 0;
      MessageBoxA((void*)0, &l, &l, 0);
    }
    because it totally omits a data segment.

    Or maybe in assembler:
    Code:
    __declspec(naked) void Entry()
    {
      _asm {
        push 0
        push esp
        push dword ptr [esp]
        push 0
        call MessageBoxA
      }  
    }
    The entire app should only consist of these directives + the include stub for MessageBoxA + the PE header. Should be about 40 bytes + the header.

    Of course, if you want it REALLY small you're better off with MASM and pure assembler.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    If you link to all these libraries, all of the STL that I have tested seems to work with the app:

    libc.lib libcp.lib msvcrt.lib kernel32.lib user32.lib

    It bloats the app from 16.0kb to 72.0kb though!

    I guess that's the price you pay for the ease of STL.

    If you don't need the STL though, ...

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    hmmm...
    I thought libc.lib is just the static version of the CRT library - and msvcrt.lib is the import lib for the dynamic version - strange that it works including both...
    libcp.lib is the static version of the C++ runtime.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width