cli::interior_ptr<Type>' to 'cli::pin_ptr<Type>'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jcvel
    New Member
    • Oct 2013
    • 3

    #1

    cli::interior_ptr<Type>' to 'cli::pin_ptr<Type>'

    Hello all:
    I am new to C++/CLI,a nd I am trying to use a native dll.
    I get the error "cannot convert from 'cli::interior_ ptr<Type>' to 'cli::pin_ptr<T ype>'"
    DLL's declaration:
    Code:
    SI_STATUS WINAPI SI_GetNumDevices(
    	LPDWORD lpdwNumDevices
    	);
    //I am pinning the pointer and call the dll with the error.
    
    pin_ptr<long int> p = &dwNumDevices;
    SI_STATUS status = SI_GetNumDevices(p);
    What'swrong here ?
    Thanks in advance !
    Last edited by Rabbit; Oct 11 '13, 05:07 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You are passing a pin_ptr<long int> to a function expecting a LPDWORD.

    However, a pin_ptr is a pointer - either const or volatile - and a long int does not qualify.

    I expect you need :

    Code:
    pin_ptr<LPDWORD> p = &dwNumDevices;
    SI_STATUS status = SI_GetNumDevices(p);

    Comment

    • jcvel
      New Member
      • Oct 2013
      • 3

      #3
      TI found the problem:

      pin_ptr<long int> p = &dwNumDevice s;// This definition is ok. The thing is that DWORD is an unsigned long int, not a long int. Changing it to 'pin_ptr<unsign ed long int> p = &dwNumDevice s;' does the job.
      I am not familiar with CLI that much.
      Thanks anyways for your reply!

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        That would make sense since LPDWORD is the address of a DWORD and a DWORD is an unsigned int.

        Considering you are in the Windows world, your pin_ptr should be a DWORD instead of an unsigned int. This may save problems should your code move to a place where a DWORD is not an unsigned int.

        Comment

        • jcvel
          New Member
          • Oct 2013
          • 3

          #5
          You are very right on that !
          I mixed the unsigned with the signed! I am an old C school yet !
          Thanks

          Comment

          Working...