问一个关于DLL函数调用的问题

sock5 2005-05-16 01:41:47
我用VC建立了一个基于MFC的DLL,主要目地是动态创建菜单,VC调用此DLL则正常
_declspec(dllexport) bool CeateMenuReal(LPCTSTR iniFile,HWND hWnd)

我在PB中如下做法是: 先在全局共享变量中声明
FUNCTION boolean CreateMenuReal(string fName,ulong windowHandle) LIBRARY "D:\Programs\VC\Menu\Debug\menu.dll"

//这里也有一个问题,我本想得到并调用的是这个函数,结果调用的只是MFC DLL中的主构造函数,该函数并没有被调用

然后在w_main的窗口中调用
long hWnd
hWnd = Handle(this)
CreateMenuReal("C:\1.ini",hWnd)

出现错误: //但是动态建立的菜单出现了,但是如下的模式对话框的错误会将程序强制中止
Appication terminated.
Error:bad runtime function reference at line 4 in click event of object cb_1 of w_main
...全文
135 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
fibbery 2005-05-16
  • 打赏
  • 举报
回复
:)恭喜
wangxichen 2005-05-16
  • 打赏
  • 举报
回复
哦 恭喜
sock5 2005-05-16
  • 打赏
  • 举报
回复
问题被解决了,原来是静态全局变量引起的错误
lzheng2001 2005-05-16
  • 打赏
  • 举报
回复
这个函数名称是否是别名,如果是请改一下声明的名称
fibbery 2005-05-16
  • 打赏
  • 举报
回复
爱小婧的那家伙是对的.
fibbery 2005-05-16
  • 打赏
  • 举报
回复
我感觉PB8的帮助比较好,有例子,上面是PB9的感觉不太一样,你自己查一下帮助.
wu_07 2005-05-16
  • 打赏
  • 举报
回复
TRY
..................
CATCH (RuntimeError er)
MessageBox("Runtime Error", er.GetMessage())
FINALLY // Add cleanup code here
Return
End TRY
fibbery 2005-05-16
  • 打赏
  • 举报
回复
Description

Isolates code that can cause an exception, describes what to do if an exception of a given type is encountered, and allows you to close files or network connections (and return objects to their original state) whether or not an exception is encountered.
Machine code If you need to build machine code DLLs, you cannot use exception handling. The process used to build machine code does not support the exception handling mechanism. Attempts to compile machine code DLLs from code that uses exception handling fail and display an error message. For more information about choosing between Pcode (PBDs) and machine code (DLLs), see the chapter on packaging your application for deployment in Application Techniques.

Syntax

TRY
trystatements
CATCH ( ThrowableType1 exIdentifier1 )
catchstatements1
CATCH ( ThrowableType2 exIdentifier2 )
catchstatements2
...
CATCH ( ThrowableTypeN exIdentifierN )
catchstatementsN
FINALLY
cleanupstatements
END TRY

Parameter Description
trystatements Block of code that might potentially throw an exception.
ThrowableTypeN Object type of exception to be caught. A CATCH block is optional if you include a FINALLY block. You can include multiple CATCH blocks. Every CATCH block in a try-catch block must include a corresponding exception object type and a local variable of that type.
exIdentifierN Local variable of type ThrowableTypeN.
catchstatementsN Code to handle the exception being caught.
cleanupstatements Cleanup code. The FINALLY block is optional if you include one or more CATCH block.
Usage

The TRY block, which is the block of statements between the TRY and CATCH keywords (or the TRY and FINALLY keywords if there is no CATCH clause), is used to isolate code that might potentially throw an exception. The statements in the TRY block are run unconditionally until either the entire block of statements is executed or some statement in the block causes an exception to be thrown.
Use a CATCH block or multiple CATCH blocks to handle exceptions thrown in a TRY block. In the event that an exception is thrown, execution of the TRY block is stopped and the statements in the first CATCH block are executed梚f and only if the exception thrown is of the same type or a descendant of the type of the identifier following the CATCH keyword.

If the exception thrown is not the same type or a descendant type of the identifier in the first CATCH block, the exception is not handled by this CATCH block. If there are additional CATCH blocks, they are evaluated in the order they appear. If the exception cannot be handled by any of the CATCH blocks, the statements in the FINALLY block are executed.
The exception then continues to unwind the call stack to any outer nested try-catch blocks. If there are no outer nested blocks, the SystemError event on the Application object is fired.

If no exception is thrown, execution continues at the beginning of the FINALLY block if one exists; otherwise, execution continues on the line following the END TRY statement.
sock5 2005-05-16
  • 打赏
  • 举报
回复
不行呀改成REF 和变量问题还是一样
还有这个TRY我不知道怎么用呀,怎么能用这个函数捕捉到这个异常并将错误忽略返回,可以写个例子嘛

现在的问题好像不是参数的问题,我跟踪DLL到内部固定到第10行零几就出现这个错误,代码全换了,也都注释了,一行代码都没有的时候问题也依旧
balloonman2002 2005-05-16
  • 打赏
  • 举报
回复
参考:
http://search.csdn.net/Expert/topic/428/428270.xml?temp=.9131739
j9dai 2005-05-16
  • 打赏
  • 举报
回复
同意楼上
TRY...CATCH...FINALLY...END TRY
fibbery 2005-05-16
  • 打赏
  • 举报
回复
楼主把配置文件放到变量里,然后再声明出声明称ref试一试。
fibbery 2005-05-16
  • 打赏
  • 举报
回复
避免出现系统运行时错误导致的引用终止可以在必要的地方加入抛出异常和异常捕获。pb8以上版本有。利用这种发放你可以试一试出现的菜单是否可用。

1,072

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧