L
Lance
That is the question.
In an unmanaged C++ DLL I'm making calls to, one of the function prototypes is
/////
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_DrawLayerList
(
HDC aDC, // Device context to draw to
GM_LayerHandle_t32* aLayerList, // List of layers to draw or NULL for all
uint32 aLayerCount, // Number of layers in list (0 for all)
GM_DrawFlags_t32 aDrawFlags, // Flags controlling how the draw is performed
const GM_Rectangle_t* aWorldBounds, // World bounds to draw or NULL for all
sint32 aLeftPixel, // Left pixel coordinate to draw to
sint32 aTopPixel, // Top pixel coordinate to draw to
sint32 aPixelWidth, // Width in pixels to draw
sint32 aPixelHeight // Height in pixels to draw
);
/////
which I originally translated to
/////
Public Declare Function GM_DrawLayerList Lib "GlobalMapperInterface" _
( _
ByVal aDC As IntPtr, _
ByRef aLayerList As GM_LayerHandle_t32, _
ByVal aLayerCount As Int32, _
ByVal aDrawFlags As GM_DrawFlags_t32, _
ByRef aWorldBounds As GM_Rectangle_t, _
ByVal aLeftPixel As Int32, _
ByVal aTopPixel As Int32, _
ByVal aPixelWidth As Int32, _
ByVal aPixelHeight As Int32 _
) As GM_Error_t32
/////
but I couldn't figure out how get it to receive NULL (I was sending IntPtr.Zero to the
function in order to represent NULL) when the 5th argument was expecting the
GM_Rectangle_t structure. NULL needs to be sent to the function in order for it to draw
all layers. So, I overloaded the function as such
/////
Public Declare Function GM_DrawLayerList Lib "GlobalMapperInterface" _
( _
ByVal aDC As IntPtr, _
ByRef aLayerList As GM_LayerHandle_t32, _
ByVal aLayerCount As Int32, _
ByVal aDrawFlags As GM_DrawFlags_t32, _
ByVal aWorldBounds As IntPtr, _
ByVal aLeftPixel As Int32, _
ByVal aTopPixel As Int32, _
ByVal aPixelWidth As Int32, _
ByVal aPixelHeight As Int32 _
) As GM_Error_t32
/////
Note the change to "ByVal" and "IntPtr" for the 5th argument. Now it accepts a NULL
argument for the 5th parameter in order to get the function to draw all layers. I suppose
that's all well and good and everything seems to work fine, but the developer of the DLL -
who admittedly is not a VB expert - thinks that there should be a better way to it in VB
so that I don't have to duplicate the function prototypes (I would imagine some function
prototypes would require more than just 1 overload. For example, I think I would need to
overload the above function declare a couple of more times to account for the second
argument - which can also receive NULL or a structure - and then any combination of the
two arguments that can receive a NULL or structure.) Is there a more efficient way to go
about this on my end?
Thanks,
Lance
In an unmanaged C++ DLL I'm making calls to, one of the function prototypes is
/////
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_DrawLayerList
(
HDC aDC, // Device context to draw to
GM_LayerHandle_t32* aLayerList, // List of layers to draw or NULL for all
uint32 aLayerCount, // Number of layers in list (0 for all)
GM_DrawFlags_t32 aDrawFlags, // Flags controlling how the draw is performed
const GM_Rectangle_t* aWorldBounds, // World bounds to draw or NULL for all
sint32 aLeftPixel, // Left pixel coordinate to draw to
sint32 aTopPixel, // Top pixel coordinate to draw to
sint32 aPixelWidth, // Width in pixels to draw
sint32 aPixelHeight // Height in pixels to draw
);
/////
which I originally translated to
/////
Public Declare Function GM_DrawLayerList Lib "GlobalMapperInterface" _
( _
ByVal aDC As IntPtr, _
ByRef aLayerList As GM_LayerHandle_t32, _
ByVal aLayerCount As Int32, _
ByVal aDrawFlags As GM_DrawFlags_t32, _
ByRef aWorldBounds As GM_Rectangle_t, _
ByVal aLeftPixel As Int32, _
ByVal aTopPixel As Int32, _
ByVal aPixelWidth As Int32, _
ByVal aPixelHeight As Int32 _
) As GM_Error_t32
/////
but I couldn't figure out how get it to receive NULL (I was sending IntPtr.Zero to the
function in order to represent NULL) when the 5th argument was expecting the
GM_Rectangle_t structure. NULL needs to be sent to the function in order for it to draw
all layers. So, I overloaded the function as such
/////
Public Declare Function GM_DrawLayerList Lib "GlobalMapperInterface" _
( _
ByVal aDC As IntPtr, _
ByRef aLayerList As GM_LayerHandle_t32, _
ByVal aLayerCount As Int32, _
ByVal aDrawFlags As GM_DrawFlags_t32, _
ByVal aWorldBounds As IntPtr, _
ByVal aLeftPixel As Int32, _
ByVal aTopPixel As Int32, _
ByVal aPixelWidth As Int32, _
ByVal aPixelHeight As Int32 _
) As GM_Error_t32
/////
Note the change to "ByVal" and "IntPtr" for the 5th argument. Now it accepts a NULL
argument for the 5th parameter in order to get the function to draw all layers. I suppose
that's all well and good and everything seems to work fine, but the developer of the DLL -
who admittedly is not a VB expert - thinks that there should be a better way to it in VB
so that I don't have to duplicate the function prototypes (I would imagine some function
prototypes would require more than just 1 overload. For example, I think I would need to
overload the above function declare a couple of more times to account for the second
argument - which can also receive NULL or a structure - and then any combination of the
two arguments that can receive a NULL or structure.) Is there a more efficient way to go
about this on my end?
Thanks,
Lance