超载还是不超载? [英] To overload, or not to overload?

查看:60
本文介绍了超载还是不超载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是问题了。


在一个非托管的C ++ DLL中我正在调用,其中一个函数原型是


/////

GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_DrawLayerList



HDC aDC,//要绘制的设备上下文

GM_LayerHandle_t32 * aLayerList,//要绘制的图层列表或所有的NULL值

uint32 aLayerCount,//列表中的图层数(0表示所有)

GM_DrawFlags_t32 aDrawFlags,//标志控制绘制的执行方式

const GM_Rectangle_t * aWorldBounds,//全局绘制界限或所有空值为
sint32 aLeftPixel,//左像素坐标绘制

sint32 aTopPixel,//要绘制的顶部像素坐标

sint32 aPixelWidth,//绘制的宽度(以像素为单位)

);

/////

我最初翻译为

/////

公共声明函数GM_DrawLa yerList Lib" GlobalMapperInterface" _

(_

ByVal aDC As IntPtr,_

ByRef aLayerList As GM_LayerHandle_t32,_

ByVal aLayerCount As Int32,_

ByVal aDrawFlags为GM_DrawFlags_t32,_

ByRef aWorldBounds为GM_Rectangle_t,_

ByVal aLeftPixel为Int32,_

ByVal aTopPixel为Int32,_

ByVal aPixelWidth为Int32,_

ByVal aPixelHeight为Int32 _

)为GM_Error_t32

/////


但我无法弄清楚如何让它接收NULL(我发送IntPtr.Zero到

函数以表示NULL)当第5个参数期望

GM_Rectangle_t结构时。需要将NULL发送到函数,以便它绘制

所有图层。所以,我这样重载了这个函数


/////

公共声明函数GM_DrawLayerList Lib" GlobalMapperInterface" _

(_

ByVal aDC As IntPtr,_

ByRef aLayerList As GM_LayerHandle_t32,_

ByVal aLayerCount As Int32,_

ByVal aDrawFlags作为GM_DrawFlags_t32,_

ByVal aWorldBounds作为IntPtr,_

ByVal aLeftPixel作为Int32,_

ByVal aTopPixel为Int32,_

ByVal aPixelWidth为Int32,_

ByVal aPixelHeight为Int32 _

)为GM_Error_t32

/////


注意对ByVal的更改和IntPtr为第五个论点。现在它接受第5个参数的NULL

参数,以便获得绘制所有图层的函数。我想

一切都很好,而且一切似乎都运行正常,但DLL的开发者 -

谁也不是VB专家 - 认为在VB中应该有一个更好的方法

这样我就不必复制函数原型了(我会想象一些函数

原型需要更多只有1个重载。例如,我想我需要

重载上面的函数声明了几次才能占第二个

参数 - 这也可以接收NULL或结构 - 然后是

两个可以接收NULL或结构的参数的任意组合。)有没有更有效的方法来关于这个我的b $ b结束?


谢谢,

Lance

解决方案

更改为ByVal aWorldBounds作为第一个版本中的GM_Rectangle_t。没有

需要通过ref传递它,因为它是一个in参数。然后只需将Nothing传递给

吧。


/ claes

" Lance" < nu *** @ business.comwrote in message

news:uG ************** @ TK2MSFTNGP04.phx.gbl ...


这就是问题。


在一个非托管的C ++ DLL中我正在调用,其中一个函数

原型是


/////

GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_DrawLayerList



HDC aDC,//要绘制的设备上下文

GM_LayerHandle_t32 * aLayerList,//要绘制的图层列表或所有空的NULL

uint32 aLayerCount,//列表中的图层(0表示所有)

GM_DrawFlags_t32 aDrawFlags,//控制绘制方式的标志

执行

const GM_Rectangle_t * aWorldBounds,/ /世界界限绘制或NULL为

所有

sint32 aLeftPixel,//绘制的左像素坐标

sint32 aTopPixel,// Top要绘制的像素坐标

sint32 aPixelWidth,//绘制的宽度(以像素为单位)

);

/////

我最初翻译为


/////

公共声明函数GM_DrawLayerList Lib" GlobalMapperInterface" _

(_

ByVal aDC As IntPtr,_

ByRef aLayerList As GM_LayerHandle_t32,_

ByVal aLayerCount As Int32,_

ByVal aDrawFlags为GM_DrawFlags_t32,_

ByRef aWorldBounds为GM_Rectangle_t,_

ByVal aLeftPixel为Int32,_

ByVal aTopPixel为Int32,_

ByVal aPixelWidth为Int32,_

ByVal aPixelHeight为Int32 _

)为GM_Error_t32

/////


但是我无法弄清楚如何让它接收NULL(我发送了

IntPtr。当第5个
参数期望GM_Rectangle_t结构时,为函数零以表示NULL。 NULL需要发送到函数的
才能绘制所有图层。所以,我这个函数超载了




/////

公共声明函数GM_DrawLayerList Lib" GlobalMapperInterface" _

(_

ByVal aDC As IntPtr,_

ByRef aLayerList As GM_LayerHandle_t32,_

ByVal aLayerCount As Int32,_

ByVal aDrawFlags作为GM_DrawFlags_t32,_

ByVal aWorldBounds作为IntPtr,_

ByVal aLeftPixel作为Int32,_

ByVal aTopPixel为Int32,_

ByVal aPixelWidth为Int32,_

ByVal aPixelHeight为Int32 _

)为GM_Error_t32

/////


注意对ByVal的更改和IntPtr为第五个论点。现在它

为第5个参数接受一个NULL参数,以便获得绘制所有图层的函数

。我认为'一切都很好,所有的东西

似乎工作得很好,但DLL的开发者 - 不可否认的是,不是一个VB
VB专家 - 认为在VB中应该有一个更好的方法,这样我就不需要复制函数原型(我会想象一些

函数原型需要更多只有1个重载。例如,

我想我需要重载上面的函数声明几次

多次来计算第二个参数 - 这也可以接收

NULL或结构 - 然后两个参数的任意组合

可以接收NULL或结构。)是否有更有效的方法去

关于这个我的结局?


谢谢,

Lance



将其更改为


/////

公共声明函数GM_DrawLayerList Lib" GlobalMapperInterface" _

(_

ByVal aDC As IntPtr,_

ByRef aLayerList As GM_LayerHandle_t32,_

ByVal aLayerCount As Int32,_

ByVal aDrawFlags为GM_DrawFlags_t32,_

ByVal aWorldBounds为GM_Rectangle_t,_

ByVal aLeftPixel为Int32,_

ByVal aTopPixel为Int32,_

ByVal aPixelWidth为Int32,_

ByVal aPixelHeight为Int32 _

)为GM_Error_t32

/////


然后发送Nothing (当然没有引号)因为第五个参数导致了一个p
PInvokeStackImbalance。


Lance

Claes Bergefall ; < lo ***** @ nospam.nospamwrote in message

news:uL ************** @ TK2MSFTNGP04.phx.gbl ...


在第一个版本中更改为ByVal aWorldBounds为GM_Rectangle_t。不需要传递它

by ref,因为它是一个in参数。然后只需传递任何东西。


/ claes


" Lance" < nu *** @ business.comwrote in message

news:uG ************** @ TK2MSFTNGP04.phx.gbl ...


>这就是问题。

在一个非托管的C ++ DLL中,我正在调用,其中一个函数原型是

/////
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_DrawLayerList

HDC aDC,//要绘制的设备上下文
GM_LayerHandle_t32 * aLayerList,//层列表到所有的绘制或NULL
uint32 aLayerCount,//列表中的层数(0表示所有)
GM_DrawFlags_t32 aDrawFlags,//控制绘制方式的标志
const GM_Rectangle_t * aWorldBounds,/ / world为所有
sint32 aLeftPixel绘制或为NULL,//左边的像素坐标绘制为
sint32 aTopPixel,//绘制的顶部像素坐标为
sint32 aPixelWidth,//宽度为要绘制的像素
sint32 aPixelHeight //高度(以像素为单位)绘制
);
/////
我最初翻译为

// /// <无线电通信公共声明函数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为GM_Rectangle_t,_
ByVal aLeftPixel为Int32,_
ByVal aTopPixel为Int32,_
ByVal aPixelWidth为Int32,_
ByVal aPixelHeight为Int32 _
)作为GM_Error_t32
/////

但我无法弄清楚如何让它接收NULL(我正在按顺序发送IntPtr.Zero到
函数当第5个参数期待
GM_Rectangle_t结构时表示NULL。需要将NULL发送到函数,以便它可以绘制所有图层。所以,我重载了这个函数

/////
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 _
)作为GM_Error_t32
/////

请注意对ByVal的更改和IntPtr为第五个论点。现在它接受第5个参数的NULL
参数,以便获得绘制所有图层的函数。我认为这一切都很好,而且一切似乎都运行良好,但DLL的开发人员 - 不可否认的是他不是VB专家 - 认为应该有更好的在VB中使用它以便我不必复制函数原型(我会想象一些函数原型需要的不仅仅是1次重载。例如,
我想我需要重载上面的函数多次声明第二个参数 - 也可以接收NULL或结构 - 然后
两个参数的任意组合可以接收NULL或结构。)有没有更有效的方法来解决这个问题?

谢谢,
Lance




嗯...如果Claes和其他少数几个A在这里被难倒,那么我猜它是'

安全到假设比过载更好的解决方案可能不存在。我知道,

它只是自原始发布以来只有5或6个小时,但我可以告诉我们什么时候没有人b / b
咬人!那就是超载了。


Lance


" Lance" < nu *** @ business.comwrote in message

news:uG ************** @ TK2MSFTNGP04.phx.gbl ...


这就是问题。


在一个非托管的C ++ DLL中我正在调用,其中一个函数原型是


/////

GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_DrawLayerList



HDC aDC,//设备要绘制的上下文

GM_LayerHandle_t32 * aLayerList,//要绘制的图层列表或所有的NULL值

uint32 aLayerCount,//列表中的图层数(0表示全部)

GM_DrawFlags_t32 aDrawFlags,//控制绘制方式的标志

const GM_Rectangle_t * aWorldBounds,//全局绘制范围或所有空值
sint32 aLeftPixel,//要绘制的左像素坐标

sint32 aTopPixel,//要绘制的顶部像素坐标

sint32 aPixelWidth,//绘制的宽度(以像素为单位) br />
sint32 aPixelHeight //用于绘制的高度(以像素为单位) />
);

/////

我最初翻译为


//// /

公共声明函数GM_DrawLayerList Lib" GlobalMapperInterface" _

(_

ByVal aDC As IntPtr,_

ByRef aLayerList As GM_LayerHandle_t32,_

ByVal aLayerCount As Int32,_

ByVal aDrawFlags为GM_DrawFlags_t32,_

ByRef aWorldBounds为GM_Rectangle_t,_

ByVal aLeftPixel为Int32,_

ByVal aTopPixel为Int32,_

ByVal aPixelWidth为Int32,_

ByVal aPixelHeight为Int32 _

)为GM_Error_t32

/////


但我无法弄清楚如何让它接收NULL(我发送IntPtr.Zero到

函数以表示NULL)当第5个参数期望

GM_Rectangle_t结构时。需要将NULL发送到函数,以便它绘制

所有图层。所以,我这样重载了这个函数


/////

公共声明函数GM_DrawLayerList Lib" GlobalMapperInterface" _

(_

ByVal aDC As IntPtr,_

ByRef aLayerList As GM_LayerHandle_t32,_

ByVal aLayerCount As Int32,_

ByVal aDrawFlags作为GM_DrawFlags_t32,_

ByVal aWorldBounds作为IntPtr,_

ByVal aLeftPixel作为Int32,_

ByVal aTopPixel为Int32,_

ByVal aPixelWidth为Int32,_

ByVal aPixelHeight为Int32 _

)为GM_Error_t32

/////


注意对ByVal的更改和IntPtr为第五个论点。现在它接受第5个参数的NULL

参数,以便获得绘制所有图层的函数。我认为'一切都很好,而且一切似乎都运行良好,但是这个DLL的开发人员 - 无可否认的是,他不是VB专家 - 认为在VB中应该有一个更好的方式

,这样我就不必复制函数原型(我会想象

一些函数原型需要更多只有1个重载。例如,我认为

我需要重载上面的函数多次声明为第二个参数的帐户

- 这也可以接收NULL或结构 - 然后是可以接收NULL或结构的两个参数的任何

组合。)是否有更多的

有效的方法来解决这个问题结束?


谢谢,

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

解决方案

Change to ByVal aWorldBounds As GM_Rectangle_t in your first version. No
need to pass it by ref since it''s an in parameter. Then just pass Nothing to
it.

/claes
"Lance" <nu***@business.comwrote in message
news:uG**************@TK2MSFTNGP04.phx.gbl...

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



Changing it 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, _
ByVal 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
/////

then sending "Nothing" (without the quotes, of course) as the 5th argument results in a
PInvokeStackImbalance.

Lance
"Claes Bergefall" <lo*****@nospam.nospamwrote in message
news:uL**************@TK2MSFTNGP04.phx.gbl...

Change to ByVal aWorldBounds As GM_Rectangle_t in your first version. No need to pass it
by ref since it''s an in parameter. Then just pass Nothing to it.

/claes
"Lance" <nu***@business.comwrote in message
news:uG**************@TK2MSFTNGP04.phx.gbl...

>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




Well drat...if Claes and the other handful of aces here are stumped, then I guess it''s
safe to assume that a better solution than overloading is likely non-existent. I know,
it''s only been about 5 or 6 hours since the original posting, but I can tell when no ones
biting! Overloading it is, then.

Lance

"Lance" <nu***@business.comwrote in message
news:uG**************@TK2MSFTNGP04.phx.gbl...

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



这篇关于超载还是不超载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆