Visual C++ 6.0 名称修改,即使在外部“C”内和 dllexport,未生成 RPC 存根

发布于 2024-12-05 21:05:53 字数 2509 浏览 0 评论 0原文

大家好,我正在致力于在旧版 Visual C++ 6.0 dll 项目中创建一个新函数,以便 C# dll 可以调用,但是由于名称修改我无法这样做,而且似乎无论我做什么我都无法阻止它,(我使用 dumpbin 来查看名称)这里是相关代码

,这是头文件的真正精简版本

#ifdef  _V7SSCOMM_CPP_
#define _DECL_V7COMM_DLL    __declspec(dllexport)
#else
#define _DECL_V7COMM_DLL    __declspec(dllimport)
#endif

#ifdef __cplusplus
extern "C" {
#endif
_DECL_V7COMM_DLL    DWORD V7ssGetFileDirInfoUnicode(LPCSTR szSign, V7_FILE_LIST_TYPE eListType, LPCSTR szServer, LPCSTR szLibrary, LPCSTR szExt, DWORD *pdwFileCnt, wchar_t *pbyFileBuf, DWORD *pdwFileBufSize);

#ifdef __cplusplus
}
#endif

#endif

,对于 cpp 文件

_DECL_V7COMM_DLL    DWORD V7ssGetFileDirInfoUnicode(LPCSTR szSign, 
                                                         V7_FILE_LIST_TYPE eListType, 
                                                         LPCSTR szServer, LPCSTR szLibrary, LPCSTR szExt, 
                                                         DWORD *pdwFileCnt, wchar_t *pbyFileBuf, DWORD *pdwFileBufSize)
{
    if (!szSign || !szServer || !szLibrary || !szExt || !pdwFileCnt || !pbyFileBuf || !pdwFileBufSize)
        return (RPC_S_INVALID_ARG);

    error_status_t Error = rpcGetFileDirInfoUnicode(
        /* [in] */ g_hRpcBinding, 
        /* [in, string] */ (unsigned char *)szSign, 
        /* [in] */ (unsigned long)eListType, 
        /* [in, string] */ (unsigned char *)szServer,
        /* [in, string] */ (unsigned char *)szLibrary,
        /* [in, string] */ (unsigned char *)szExt,
        /* [out] */ (unsigned long *)pdwFileCnt, 
        /* [out, size_is(*pdwFileBufSize)] */ (wchar_t *)pbyFileBuf, 
        /* [in, out] */ (unsigned long *)pdwFileBufSize);

    return (Error);
} // end V7ssGetFileDirInfoUnicode()

dumpbin 返回以下内容 1 0 00001401 ?V7ssGetFileDirInfoUnicode@@YAKPBDW4tag_V7_FILE_LIST_TYPE@@000PAKPAG2@Z

不是我想要的,理想情况下它只会是 V7ssGetFileDirInfoUnicode

据我所知,从我一直在阅读的内容来看,我尝试这样做意味着我不需要在 .def 文件中定义它。奇怪的是,我遵循与正确显示的预先存在的功能相同的精确设置。

如果有任何帮助,我将不胜感激。谢谢!

更新

.def 文件选项只要不进行名称修改即可工作,也就是说 MIDL 编译器不会创建 RPC 存根,我认为这两个问题是相关的。

这里还有 MIDL 版本,取自 C 文件本身

/* this ALWAYS GENERATED file contains the RPC server stubs */


/* File created by MIDL compiler version 5.01.0164 */
/* at Wed Sep 21 08:57:22 2011
 */
/* Compiler settings for V7Rpc.idl:
    Os (OptLev=s), W1, Zp8, env=Win32, ms_ext, c_ext
    error checks: allocation ref bounds_check enum stub_data 
*/
//@@MIDL_FILE_HEADING(  )

Hey guys im working on creating a new function in legacy visual C++ 6.0 dll project, so that a C# dll can call into, however i unable to do so due to name mangling and it seems no matter what I do I can't stop it, (i used dumpbin to view the names) here is the relevant code

this is a really trimmed down verstion of the header file

#ifdef  _V7SSCOMM_CPP_
#define _DECL_V7COMM_DLL    __declspec(dllexport)
#else
#define _DECL_V7COMM_DLL    __declspec(dllimport)
#endif

#ifdef __cplusplus
extern "C" {
#endif
_DECL_V7COMM_DLL    DWORD V7ssGetFileDirInfoUnicode(LPCSTR szSign, V7_FILE_LIST_TYPE eListType, LPCSTR szServer, LPCSTR szLibrary, LPCSTR szExt, DWORD *pdwFileCnt, wchar_t *pbyFileBuf, DWORD *pdwFileBufSize);

#ifdef __cplusplus
}
#endif

#endif

and for the cpp file

_DECL_V7COMM_DLL    DWORD V7ssGetFileDirInfoUnicode(LPCSTR szSign, 
                                                         V7_FILE_LIST_TYPE eListType, 
                                                         LPCSTR szServer, LPCSTR szLibrary, LPCSTR szExt, 
                                                         DWORD *pdwFileCnt, wchar_t *pbyFileBuf, DWORD *pdwFileBufSize)
{
    if (!szSign || !szServer || !szLibrary || !szExt || !pdwFileCnt || !pbyFileBuf || !pdwFileBufSize)
        return (RPC_S_INVALID_ARG);

    error_status_t Error = rpcGetFileDirInfoUnicode(
        /* [in] */ g_hRpcBinding, 
        /* [in, string] */ (unsigned char *)szSign, 
        /* [in] */ (unsigned long)eListType, 
        /* [in, string] */ (unsigned char *)szServer,
        /* [in, string] */ (unsigned char *)szLibrary,
        /* [in, string] */ (unsigned char *)szExt,
        /* [out] */ (unsigned long *)pdwFileCnt, 
        /* [out, size_is(*pdwFileBufSize)] */ (wchar_t *)pbyFileBuf, 
        /* [in, out] */ (unsigned long *)pdwFileBufSize);

    return (Error);
} // end V7ssGetFileDirInfoUnicode()

dumpbin returns the following
1 0 00001401 ?V7ssGetFileDirInfoUnicode@@YAKPBDW4tag_V7_FILE_LIST_TYPE@@000PAKPAG2@Z

not what i wanted ideally it would only be V7ssGetFileDirInfoUnicode

As far as i can tell and from what i have been reading the way i trying to do this means i don't need to define this in the .def file. What is odd, is im following the same extact setup as pre-existing functions that show up correctly.

I would be grateful for any help.Thanks!

Update

the .def file option works as far as not name mangling, that being said the MIDL compiler is not creating the RPC stub, I think these two issues are related.

also here is the MIDL version, taken from the C file iteself

/* this ALWAYS GENERATED file contains the RPC server stubs */


/* File created by MIDL compiler version 5.01.0164 */
/* at Wed Sep 21 08:57:22 2011
 */
/* Compiler settings for V7Rpc.idl:
    Os (OptLev=s), W1, Zp8, env=Win32, ms_ext, c_ext
    error checks: allocation ref bounds_check enum stub_data 
*/
//@@MIDL_FILE_HEADING(  )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情定在深秋 2024-12-12 21:05:53

如果您确定包含了 .cpp 文件中的头文件,那么您可以尝试将 .def 文件添加到您的项目中。可能还有其他方法,但这似乎始终是减少导出中名称损坏的关键部分。内容看起来像这样。

EXPORTS
   V7ssGetFileDirInfoUnicode

If you are certain that you included the header file from the .cpp file, then you might try adding a .def file to your project. There might be other ways, but that has always seemed to be a critical part in reducing the name mangling in the exports. The contents would look something like this.

EXPORTS
   V7ssGetFileDirInfoUnicode
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文