dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Converting 32-bit into 64

  1. #1
    Join Date
    Apr 2005
    Posts
    1,828

    Converting 32-bit into 64

    I have a sample code.

    Code:
    static DWORD CALLBACK StreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
    	{
            DWORD dwRead(0);
    
    		if(SUCCEEDED(g_pTextFile->Read(pbBuff, cb, dwRead)))
    		{
                *pcb = LONG(dwRead);
    
    			return 0;
    		}
    
    		return 1;
    	}
    It works fine in 32-bit environment. But when I convert the whole project into 64-bit, I come across this error.

    Error 1 error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK' c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h 70
    Error 2 error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK' c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h 70
    Error 3 error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK' c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h 70
    Error 4 error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK' c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h 70
    Error 5 error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK' c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h 70
    Error 6 error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK' c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h 70
    Error 44 error C2440: '=' : cannot convert from 'DWORD (__cdecl *)(DWORD,LPBYTE,LONG,LONG *)' to 'EDITSTREAMCALLBACK' c:\maverick\projects\ccpm\src\main_ccpm_11.0.0.7\LicenseBox.h 70
    While using this function

    Code:
    EDITSTREAM es;
    ZeroMemory(&es, sizeof(EDITSTREAM));
    es.pfnCallback = StreamInCallback;
    Can someone suggest me change in this code so that I can resolve this error in 64-bit?
    Last edited by maverick786us; August 20th, 2015 at 05:44 AM.

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Converting 32-bit into 64

    you need to use the right function prototype when in Win64.
    The one you use here appears to be tailored to Win32. In Win64 pointers are 64bit pointers, and values like DWORD and LONG are typically 64bit as well.

    so rough guess:
    this function should return a 64bit unsigned in type (DWORD_PTR ?) instead of a DWORD,
    the DWORD dwRead is probably also supposed to be a 64bit unsigned integer (DWORD_PTR ?)

    but you'll have to look up the right function prototype and adjust the code accordingly. either by matching it to 64bit specifically, or by using the compatibility types that allow building your app in both 32Bit and 64bit versions.

  3. #3
    Join Date
    Jan 2007
    Posts
    102

    Re: Converting 32-bit into 64

    Relevant. A common error occurring when compiling a 64-bit application: error C2440, OnTimer: http://www.viva64.com/en/k/0011/

  4. #4
    Join Date
    Apr 2005
    Posts
    1,828

    Re: Converting 32-bit into 64

    Quote Originally Posted by OReubens View Post
    you need to use the right function prototype when in Win64.
    The one you use here appears to be tailored to Win32. In Win64 pointers are 64bit pointers, and values like DWORD and LONG are typically 64bit as well.

    so rough guess:
    this function should return a 64bit unsigned in type (DWORD_PTR ?) instead of a DWORD,
    the DWORD dwRead is probably also supposed to be a 64bit unsigned integer (DWORD_PTR ?)

    but you'll have to look up the right function prototype and adjust the code accordingly. either by matching it to 64bit specifically, or by using the compatibility types that allow building your app in both 32Bit and 64bit versions.
    So you are saying that if I change the function to this.

    Code:
    static DWORD_PTR CALLBACK StreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
    	{
            DWORD_PTR dwRead(0);
    
    		if(SUCCEEDED(g_pTextFile->Read(pbBuff, cb, dwRead)))
    		{
                *pcb = LONG(dwRead);
    
    			return 0;
    		}
    
    		return 1;
    	}
    It will resolve the issue? (if we ignore other complications behind)
    Last edited by maverick786us; August 21st, 2015 at 01:12 AM.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Converting 32-bit into 64

    No, I'm saying you need to LOOK UP the actual prototype for this function and match it accordingly. I only made some suggestions where there are likely mismatches, but it's entirely possible that cookie is indeed a 32bit value and/or the return is 32bit, even in Win64.

    additionally since this code was never written with Win64 in mind, you also need to review what is happening inside those functions and whether that is still correct/valid in a Win64 setting.

    for example, all typecasts are potential pitfalls. so that *pcb = LONG(dwRead); could be a problem too (I'm not saying it is, it isn't my code). And that's partly the reason why you want to avoid C-style typecasts... they're non-Obvious to spot. A good Lint type tool may help you locate the places where such casts are being used.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)