Steppenwolf
New member
How do I retrieve a string / char() value from a dll which only accepts IntPtr(at least all my other attempts failed with eroors) as Variable.
I have a perfectly fine working c/c++ code to call the c-type dll which goes as follows (Hope I include all the relevant parts):
typedef KPDCStatus (*KPDCGetAttributeInfoFunc)(
KPDCOpaqueRef inRef,
KPDCAttributeID inAttrID,
KPDCDataType *outAttrType,
KPDCUInt32 *outAttrSize);
typedef KPDCStatus (*KPDCGetAttributeValueFunc)(
KPDCOpaqueRef inRef,
KPDCAttributeID inAttrID,
KPDCUInt32 *inOutAttrSize,
void* outAttrValue);
//The functions are loaded into the theProcs-Structure
char theMemoryPath[255];
theStatus = theProcs.GetAttributeInfo(theCamera, KPDCSerialNumberStringID,&theDataType, &theAttributeSize );
// Now get actual serial number and store it in the memory path
memset(theMemoryPath, 0, sizeof(theMemoryPath) );
theStatus = theProcs.GetAttributeValue( theCamera, KPDCSerialNumberStringID,&theAttributeSize, theMemoryPath);
The function returns : P14N-15076 (Thats what I want)
Trying to transfer this call to VB.net my current version looks like this (aftertaking many forms in the meantime, trying some MarshalAs and whatever I read about the topic):
<DllImport("DCSPro4SLR.dll")> Shared Function KPDCGetAttributeInfo(ByVal inRef As IntPtr, _
ByVal inAttrID As UInt32, ByRef outAttrType As UInt32, ByRef outAttrSize As UInt32) As Integer
End Function
<DllImport("DCSPro4SLR.dll")> Shared Function KPDCGetAttributeValue(ByVal inRef As IntPtr, _
ByVal inAttrID As UInt32, ByRef inOutAttrSize As UInt32, ByRef outAttrValue As IntPtr) As Integer
End Function
The KPDCGetAttributeValue Function is the one troubling me
Private sub Test
theStatus = KPDCGetAttributeInfo(theCamera, Convert.ToUInt32(KPDCCamAttr.KPDCSerialNumberStringID), _
theDataType, theAttributeSize)
Dim tmpMemPath As IntPtr = Nothing
theMemoryPath = ""
theStatus = KPDCGetAttributeValue(theCamera, Convert.ToUInt32(KPDCCamAttr.KPDCSerialNumberStringID), _
theAttributeSize, tmpMemPath)
end sub
Everything seems to work fine. The returned status is OK, similar to the c call, theAttributeSize changes from 11 to 10, but I cant find a way to get the string value based on the tmpMemPath = 1312043344 value returned by the function.
E.g. trying:
theMemoryPath = Marshal.PtrToStringAuto(tmpMemPath)
yields "" while all the other versions of Marhal.PtrToString...(tmpMemPath [,]) result in an reference not set to an object exception.
Just ask if additional information is needed.
I have a perfectly fine working c/c++ code to call the c-type dll which goes as follows (Hope I include all the relevant parts):
typedef KPDCStatus (*KPDCGetAttributeInfoFunc)(
KPDCOpaqueRef inRef,
KPDCAttributeID inAttrID,
KPDCDataType *outAttrType,
KPDCUInt32 *outAttrSize);
typedef KPDCStatus (*KPDCGetAttributeValueFunc)(
KPDCOpaqueRef inRef,
KPDCAttributeID inAttrID,
KPDCUInt32 *inOutAttrSize,
void* outAttrValue);
//The functions are loaded into the theProcs-Structure
char theMemoryPath[255];
theStatus = theProcs.GetAttributeInfo(theCamera, KPDCSerialNumberStringID,&theDataType, &theAttributeSize );
// Now get actual serial number and store it in the memory path
memset(theMemoryPath, 0, sizeof(theMemoryPath) );
theStatus = theProcs.GetAttributeValue( theCamera, KPDCSerialNumberStringID,&theAttributeSize, theMemoryPath);
The function returns : P14N-15076 (Thats what I want)
Trying to transfer this call to VB.net my current version looks like this (aftertaking many forms in the meantime, trying some MarshalAs and whatever I read about the topic):
<DllImport("DCSPro4SLR.dll")> Shared Function KPDCGetAttributeInfo(ByVal inRef As IntPtr, _
ByVal inAttrID As UInt32, ByRef outAttrType As UInt32, ByRef outAttrSize As UInt32) As Integer
End Function
<DllImport("DCSPro4SLR.dll")> Shared Function KPDCGetAttributeValue(ByVal inRef As IntPtr, _
ByVal inAttrID As UInt32, ByRef inOutAttrSize As UInt32, ByRef outAttrValue As IntPtr) As Integer
End Function
The KPDCGetAttributeValue Function is the one troubling me
Private sub Test
theStatus = KPDCGetAttributeInfo(theCamera, Convert.ToUInt32(KPDCCamAttr.KPDCSerialNumberStringID), _
theDataType, theAttributeSize)
Dim tmpMemPath As IntPtr = Nothing
theMemoryPath = ""
theStatus = KPDCGetAttributeValue(theCamera, Convert.ToUInt32(KPDCCamAttr.KPDCSerialNumberStringID), _
theAttributeSize, tmpMemPath)
end sub
Everything seems to work fine. The returned status is OK, similar to the c call, theAttributeSize changes from 11 to 10, but I cant find a way to get the string value based on the tmpMemPath = 1312043344 value returned by the function.
E.g. trying:
theMemoryPath = Marshal.PtrToStringAuto(tmpMemPath)
yields "" while all the other versions of Marhal.PtrToString...(tmpMemPath [,]) result in an reference not set to an object exception.
Just ask if additional information is needed.