2

I have an exposed method that accepts a long* as a parameter like this:

void  MyClass::MyPublicMethod(long *pLong) 

Inside this method, I call a system API that accepts an INT64*, like this:

void  MyClass::MyPublicMethod(long *pLong) 
{
    //SomeAPI::APIMethod(INT64* p64);
    SomeAPI::APIMethod(&pLong);
}

When compiling as x64, I get an error (rightly so):

error C2664: 'SomeAPI::APIMethod(int64* p64)': cannot convert argument 1 from 'long*' to 'INT64*'

I do not want to change my exposed method's signature because it will have many downstream consequences. What is the best way to address this situation, assuming that I know that p64 will not exceed the limits of a long?

Something like this?

void  MyClass::MyPublicMethod(long *pLong) 
{
    // Use a local INT64 for the API call.
    INT64 tmp64 = *pLong;
    //SomeAPI::APIMethod(INT64* p64);
    SomeAPI::APIMethod(&tmp64);
    *pLong = (long)tmp64;
}
BarryE
  • 29
  • 1

1 Answers1

-1

I think what you are seeing is a manifestation of the fact the sizeof(long) on the platform you are testing, which I presume is Windows, is 32 bit (as opposed to 64). You can try testing that premise.

If that is true, you may want to pass in long long which should be 64 bit. You will then have to change the method signature.

As a side note, when you write this,

    *pLong = (long)tmp64;

You are typecasting a 64-bit value to 32-bit's. Is there a guarantee that the APIMethod is always returning a 32-bit value. If not, that's a problem.

funkysidd
  • 64
  • 6