{"id":286,"date":"2021-03-15T15:09:13","date_gmt":"2021-03-15T07:09:13","guid":{"rendered":"http:\/\/liyanliang.net\/?p=286"},"modified":"2021-03-15T15:24:52","modified_gmt":"2021-03-15T07:24:52","slug":"loadlibraryandgetprocaddress","status":"publish","type":"post","link":"http:\/\/liyanliang.net\/index.php\/2021\/03\/15\/loadlibraryandgetprocaddress\/","title":{"rendered":"\u4eceDLL\u4e2d\u52a8\u6001\u52a0\u8f7d\u4e00\u4e2a\u51fd\u6570\uff1aLoadLibrary\u548cGetProcAddress\u7684\u4f7f\u7528"},"content":{"rendered":"\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><strong>\u80cc\u666f\u63cf\u8ff0\uff1a<\/strong><\/p>\n\n\n\n<p>\u5728\u9879\u76eeCDP_cmd\u4e2d\u9700\u8981\u8c03\u7528\u9879\u76eeCDP_dgnCalc\u4e2d\u7684\u7c7bCAnalRstHelper_JTGTJ212011\u7684\u51fd\u6570:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">BOOL GetElemValuePositiveOrNegativeMy(IN OUT TElemPosition&amp; tElemPos,OUT double&amp; dCtrlValue, BOOL bPositive);<\/pre>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<p><strong>1.\u5728CAnalRstHelper_JTGTJ212011.cpp\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u5168\u5c40\u51fd\u6570\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">EXTERN_C __declspec(dllexport) BOOL GetElemValuePositiveOrNegativeMyGlobal(CNSDocBase* pDoc, IN OUT TElemPosition&amp; tElemPos,OUT double&amp; dCtrlValue, BOOL bPositive)\n{\n    CAnalRstHelper_JTGTJ212011 helper(pDoc);\n    return helper.GetElemValuePositiveOrNegativeMy(tElemPos, dCtrlValue, bPositive);\n}<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">\u6ce8\u610f\uff0c\u5fc5\u987b\u8981\u5728\u5168\u5c40\u51fd\u6570\u524d\u6dfb\u52a0 EXTERN_C\uff0c\u5426\u5219\u51fd\u6570\u867d\u7136\u5bfc\u51fa\u4e86\uff0c\u5374\u65e0\u6cd5\u8c03\u7528\u8be5\u51fd\u6570\u3002<\/pre>\n\n\n\n<p><strong>2.\u5728\u9879\u76eeCDP_cmd\u7684\u7c7bCCMCtseDlg.h\u4e2d\u5b9a\u4e49\u51fd\u6570\u6307\u9488<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">typedef  BOOL (*lpfnGetElemValuePositiveOrNegativeMy)(CNSDocBase* pDoc, IN OUT TElemPosition&amp; tElemPos,OUT double&amp; dCtrlValue, BOOL bPositive);<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u7684\u51fd\u6570\u53c2\u6570\u5217\u8868\u4e0e\u88ab\u8c03\u7528\u7684\u51fd\u6570\u5217\u8868\u4e00\u81f4\u5373\u53ef\u3002<\/p>\n\n\n\n<p><strong>3.\u5728\u9879\u76eeCDP_cmd\u7684\u7c7bCCMCtseDlg.cpp\u4e2d\u8c03\u7528<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">BOOL CCMCtseDlg::GetMaxPositiveOrMinNegativeMy() const\n{\n    \/\/ \u52a0\u8f7ddll\n    HMODULE hDgnCalcHandle = ::LoadLibrary(_T(\"CDP_dgnCalc.dll\")); \n    if (!hDgnCalcHandle)\n    {\n        ASSERT(0);\n        return FALSE;\n    }\n    \n    \/\/ \u83b7\u53d6\u51fd\u6570\u6307\u9488\n    lpfnGetElemValuePositiveOrNegativeMy g_pGetElemValuePositiveOrNegativeMy;\n    g_pGetElemValuePositiveOrNegativeMy = (lpfnGetElemValuePositiveOrNegativeMy)GetProcAddress(hDgnCalcHandle, \"GetElemValuePositiveOrNegativeMyGlobal\");\n    \n    \/\/ \u8c03\u7528\u51fd\u6570\n    if (!g_pGetElemValuePositiveOrNegativeMy(m_pDoc, curElemPos, dCurElemMy, bPositive))\n    {\n        FreeLibrary(hDgnCalcHandle);\n        hDgnCalcHandle = NULL;\n        ASSERT(0);\n        return FALSE;\n    }\n    return TRUE;\n}<\/pre>\n\n\n\n<p><strong>4.\u4f7f\u7528 DependencyWalker \u53cd\u7f16\u8bd1\u5de5\u5177\u67e5\u770b\u5168\u5c40\u51fd\u6570 GetElemValuePositiveOrNegativeMyGlobal \u662f\u5426\u5bfc\u51fa<\/strong><\/p>\n\n\n\n<p>\u5728Debug\u6587\u4ef6\u5939\u4e0b\u627e\u5230 CDP_dgnCalc.dll \uff0c\u62d6\u62fd\u5230DependencyWalker\u754c\u9762\u4e2d\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20210315150214.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u641c\u7d22GetElemValuePositiveOrNegativeMyGlobal\uff0c \u8bf4\u660e\u51fd\u6570\u5df2\u5bfc\u51fa\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20210315150309.png\" alt=\"\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f\u63cf\u8ff0\uff1a \u5728\u9879\u76eeCDP_cmd\u4e2d\u9700\u8981\u8c03\u7528\u9879\u76eeCDP_dgnCalc\u4e2d\u7684\u7c7bCAnalRstHelper_JTGTJ212011\u7684\u51fd\u6570: \u89e3\u51b3\u65b9\u6cd5\uff1a 1.\u5728CAnalRstHelper_JTGTJ212011.cpp\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u5168\u5c40\u51fd\u6570\uff1a \u6ce8\u610f\uff0c\u5fc5\u987b\u8981\u5728\u5168\u5c40\u51fd\u6570\u524d\u6dfb\u52a0 EXTERN_C\uff0c\u5426\u5219\u51fd\u6570\u867d\u7136\u5bfc\u51fa\u4e86\uff0c\u5374\u65e0\u6cd5\u8c03\u7528\u8be5\u51fd\u6570\u3002 2.\u5728\u9879\u76eeCDP_cmd\u7684\u7c7bCCMCtseDlg.h\u4e2d\u5b9a\u4e49\u51fd\u6570\u6307\u9488 \u8fd9\u91cc\u7684\u51fd\u6570\u53c2\u6570\u5217\u8868\u4e0e\u88ab\u8c03\u7528\u7684\u51fd\u6570\u5217\u8868\u4e00\u81f4\u5373\u53ef\u3002 3.\u5728\u9879\u76eeCDP_cmd\u7684\u7c7bCCMCtseDlg.cpp\u4e2d\u8c03\u7528 4.\u4f7f\u7528 DependencyWalker \u53cd\u7f16\u8bd1\u5de5\u5177\u67e5\u770b\u5168\u5c40\u51fd\u6570 GetElemValuePositiveOrNegativeMyGlobal \u662f\u5426\u5bfc\u51fa \u5728Debug\u6587\u4ef6\u5939\u4e0b\u627e\u5230 CDP_dgnCalc.dll \uff0c\u62d6\u62fd\u5230DependencyWalker\u754c\u9762\u4e2d\uff1a \u6587\u672c\u7f16\u8f91\u5668\u4e2d\u641c\u7d22GetElemValuePositiveOrNegativeMyGlobal\uff0c \u8bf4\u660e\u51fd\u6570\u5df2\u5bfc\u51fa\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[34],"class_list":["post-286","post","type-post","status-publish","format-standard","hentry","category-c","tag-dll"],"_links":{"self":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts\/286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/comments?post=286"}],"version-history":[{"count":3,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts\/286\/revisions"}],"predecessor-version":[{"id":290,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts\/286\/revisions\/290"}],"wp:attachment":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/media?parent=286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/categories?post=286"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/tags?post=286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}