473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

3
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<Type>'"
DLL's declaration:
Expand|Select|Wrap|Line Numbers
  1. SI_STATUS WINAPI SI_GetNumDevices(
  2.     LPDWORD lpdwNumDevices
  3.     );
  4. //I am pinning the pointer and call the dll with the error.
  5.  
  6. pin_ptr<long int> p = &dwNumDevices;
  7. SI_STATUS status = SI_GetNumDevices(p);
What'swrong here ?
Thanks in advance !
Oct 11 '13 #1
4 2795
weaknessforcats
9,208 Expert Mod 8TB
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 :

Expand|Select|Wrap|Line Numbers
  1. pin_ptr<LPDWORD> p = &dwNumDevices;
  2. SI_STATUS status = SI_GetNumDevices(p);
  3.  
Oct 11 '13 #2
jcvel
3
TI found the problem:

pin_ptr<long int> p = &dwNumDevices;// This definition is ok. The thing is that DWORD is an unsigned long int, not a long int. Changing it to 'pin_ptr<unsigned long int> p = &dwNumDevices;' does the job.
I am not familiar with CLI that much.
Thanks anyways for your reply!
Oct 11 '13 #3
weaknessforcats
9,208 Expert Mod 8TB
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.
Oct 11 '13 #4
jcvel
3
You are very right on that !
I mixed the unsigned with the signed! I am an old C school yet !
Thanks
Oct 11 '13 #5

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.