Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Having a generic function GetProcAddress for both unicode and ascii builds - fails in release mode

Having a generic function GetProcAddress for both unicode and ascii builds - fails in release mode

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcomhardwaredebugging
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Priya_Sundar
    wrote on last edited by
    #1

    Hi All, I am having a common code snippet to be compiled in VC6 and in Embedded vc++(CE). Right now i am working with vc6 part.

    void* CNewClass::GetProcAddress1(HMODULE hModule, LPCTSTR lpFuncName)
    {
    USES_CONVERSION;//for ATL, to use A2W declare this first

    #ifdef \_WINCE	//for wince
    	LPCWSTR lpUnicodeFuncName = A2W( lpFuncName );
    	return(GetProcAddress(hModule, lpUnicodeFuncName));
    #else // for vc6
    	LPCSTR lpAsciiFuncName = (LPCSTR)W2A( lpFuncName );
    	return (GetProcAddress(hModule, lpAsciiFuncName));
    #endif
    

    }

    Problem: This function (GetProcAddress) returns 0/fails in release mode. It works fine in debug mode. General Info: The function GetProcAddress resolves to GetProcAddressA or GetProcAddressW based on the build(ascii or unicode) in EVC++ whereas in vc6, it is GetProcAddress only (simlar to GetProcAddressA with LPCSTR as second parameter). Also just FYI: http://blog.voidnish.com/?p=70[^] I tried lot of ways to typecastings.. but didnot work. Please help.

    Priya Sundar

    I CPalliniC 2 Replies Last reply
    0
    • P Priya_Sundar

      Hi All, I am having a common code snippet to be compiled in VC6 and in Embedded vc++(CE). Right now i am working with vc6 part.

      void* CNewClass::GetProcAddress1(HMODULE hModule, LPCTSTR lpFuncName)
      {
      USES_CONVERSION;//for ATL, to use A2W declare this first

      #ifdef \_WINCE	//for wince
      	LPCWSTR lpUnicodeFuncName = A2W( lpFuncName );
      	return(GetProcAddress(hModule, lpUnicodeFuncName));
      #else // for vc6
      	LPCSTR lpAsciiFuncName = (LPCSTR)W2A( lpFuncName );
      	return (GetProcAddress(hModule, lpAsciiFuncName));
      #endif
      

      }

      Problem: This function (GetProcAddress) returns 0/fails in release mode. It works fine in debug mode. General Info: The function GetProcAddress resolves to GetProcAddressA or GetProcAddressW based on the build(ascii or unicode) in EVC++ whereas in vc6, it is GetProcAddress only (simlar to GetProcAddressA with LPCSTR as second parameter). Also just FYI: http://blog.voidnish.com/?p=70[^] I tried lot of ways to typecastings.. but didnot work. Please help.

      Priya Sundar

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      Should the

      LPCSTR lpAsciiFuncName = (LPCSTR)W2A( lpFuncName );

      line be:

      LPCSTR lpAsciiFuncName = (LPCSTR)T2A( lpFuncName );

      ? That may not be the source of your trouble, but it won't help... Iain.

      In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job! http://cv.imcsoft.co.uk/[^]

      1 Reply Last reply
      0
      • P Priya_Sundar

        Hi All, I am having a common code snippet to be compiled in VC6 and in Embedded vc++(CE). Right now i am working with vc6 part.

        void* CNewClass::GetProcAddress1(HMODULE hModule, LPCTSTR lpFuncName)
        {
        USES_CONVERSION;//for ATL, to use A2W declare this first

        #ifdef \_WINCE	//for wince
        	LPCWSTR lpUnicodeFuncName = A2W( lpFuncName );
        	return(GetProcAddress(hModule, lpUnicodeFuncName));
        #else // for vc6
        	LPCSTR lpAsciiFuncName = (LPCSTR)W2A( lpFuncName );
        	return (GetProcAddress(hModule, lpAsciiFuncName));
        #endif
        

        }

        Problem: This function (GetProcAddress) returns 0/fails in release mode. It works fine in debug mode. General Info: The function GetProcAddress resolves to GetProcAddressA or GetProcAddressW based on the build(ascii or unicode) in EVC++ whereas in vc6, it is GetProcAddress only (simlar to GetProcAddressA with LPCSTR as second parameter). Also just FYI: http://blog.voidnish.com/?p=70[^] I tried lot of ways to typecastings.. but didnot work. Please help.

        Priya Sundar

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        On my system this code (following Iain's suggestion), compiled with VC6 works fine both on Debug and Release build

        LPCSTR lpAsciiFuncName = T2A( lpFuncName );
        return (GetProcAddress(hModule, lpAsciiFuncName));

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        P 1 Reply Last reply
        0
        • CPalliniC CPallini

          On my system this code (following Iain's suggestion), compiled with VC6 works fine both on Debug and Release build

          LPCSTR lpAsciiFuncName = T2A( lpFuncName );
          return (GetProcAddress(hModule, lpAsciiFuncName));

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          P Offline
          P Offline
          Priya_Sundar
          wrote on last edited by
          #4

          Hi, Still it is not working after using T2A(). And fyi I am compiling my application(vc6) in UNICODE! Could you please show me your function call? The below is my function call:

          CString CompletePathOfDll ="E:\\sample.dll";
          HINSTANCE DllHandle = LoadLibrary(CompletePathOfDll);//loads the dll successfully

          if (DllHandle != NULL)
          {
          int IsCorrectDll=(int)GetProcAddress1(DllHandle ,TEXT("Get_Data_Function"));
          if(IsCorrectDll>0)
          {
          //do something
          }
          }

          Thanks.

          Priya Sundar

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups