Thread: LoadLibrary return..

  1. #1
    Registered User
    Join Date
    Jun 2008
    Location
    Brazil
    Posts
    2

    Question LoadLibrary return..

    Hi ppl, i'm new here and this is my first post.

    I got this code and it works fine! It just set "myprinter" as default printer.

    Code:
    HINSTANCE lib;
    	lib = LoadLibrary("printui.dll");
    	if ( lib == NULL ) {
    		printf("%s\n", "printui.dll");
    		return 0;
    	}
    	LPFUNC PrintUIEntry;
    	PrintUIEntry = (LPFUNC)GetProcAddress(lib, "PrintUIEntryW");
    	if ( PrintUIEntry == NULL ) {
    		FreeLibrary( lib );
    		printf("%s\n", "PrintUIEntry");
    		return 0;
    	}
    	_bstr_t bstrParam;
    	bstrParam = " /y /n \"myprinter\"";
    
    	PrintUIEntry(
    		GetDesktopWindow(),
    		lib,
    		(wchar_t *)bstrParam,
    		SW_SHOW
    	);
    	
    	FreeLibrary( lib );
    But i need to know if it worked. I need an exit code, or boolean response.

    Someone knows how to retrieve it?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I can't find the function PrintUIEntry at MSDN, but I'd expect it to return something, so check for return after calling your function pointer.

    T ret = PrintUIEntry(
    GetDesktopWindow(),
    lib,
    (wchar_t *)bstrParam,
    SW_SHOW
    );
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Location
    Brazil
    Posts
    2

    Thumbs up

    I can't find either. But I solved it this morning.
    I missed a part of my code:

    typedef void (__stdcall *LPFUNC)
    (
    HWND hwnd,
    HINSTANCE hinst,
    LPWSTR lpszCmdLine,
    int nCmdShow
    );
    Well, a void will never return any value, right?

    then... I changed:

    typedef int (__stdcall *LPFUNC)
    (
    HWND hwnd,
    HINSTANCE hinst,
    LPWSTR lpszCmdLine,
    int nCmdShow
    );
    And, works fine:

    int ret = PrintUIEntry(
    GetDesktopWindow(),
    lib,
    (wchar_t *)bstrParam,
    SW_SHOW
    );
    Sorry about my mistake.

    Tks for your help!

    Raphael

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  3. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM
  5. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM

Tags for this Thread