错误:全局范围没有 GetUrl

发布于 2024-09-29 18:01:16 字数 1324 浏览 7 评论 0原文

我的 C++ DLL 有一个新问题...我尝试导出整个类而不是仅导出一种方法。但程序现在不想编译,因为全局范围没有 GetUrl
这是我的“UrlConnector.h”: <代码>

#define ConnectMe __declspec( dllexport )

命名空间 ConnectHttps { 连接我类 { void GetUrl(char *url, unsigned int bufferLength); }; }


and here is the part of my UrlConnector.cpp that isn't compiling:
#include "UrlConnector.h"
#include "MyConnectionClass.h"
#include 
using namespace std;

命名空间 ConnectHttps { void ConnectMe::GetUrl(char* url, 无符号 bufferLength) { MyConnectionClass initSec; 字符串响应 = initSec.GetResult(); strncpy_s(url,bufferLength,response.c_str(),response.length()); } }

Now, I would like to be able to create an DLL from this, and I would like to make a test program to call the class and the method GetUrl from a dll. I'm using Visual Studio 2010 with Visual C++ DLL.
I've also managed to read this from the MSDN and this tutorial as well, but I just can't seem to get it to work! I would really appreciate any help!

I have a new problem with my C++ DLL... I have tried exporting the entire class instead of only one method. But the program doesn't want to compile now because of that the global scope has no GetUrl

Here is my "UrlConnector.h":

#define ConnectMe __declspec( dllexport )

namespace ConnectHttps { class ConnectMe { void GetUrl(char *url, unsigned int bufferLength); }; }



and here is the part of my UrlConnector.cpp that isn't compiling:

#include "UrlConnector.h"
#include "MyConnectionClass.h"
#include 
using namespace std;

namespace ConnectHttps { void ConnectMe::GetUrl(char* url, unsigned bufferLength) { MyConnectionClass initSec; string response = initSec.GetResult(); strncpy_s(url, bufferLength, response.c_str(), response.length()); } }


Now, I would like to be able to create an DLL from this, and I would like to make a test program to call the class and the method GetUrl from a dll. I'm using Visual Studio 2010 with Visual C++ DLL.
I've also managed to read this from the MSDN and this tutorial as well, but I just can't seem to get it to work!
I would really appreciate any help!

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

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

发布评论

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

评论(1

旧人哭 2024-10-06 18:01:16

除非我弄错了,否则你似乎没有给你的班级命名。
你使 ConnectMe 不是一个类名,而是一个宏来导出你的类,但你的类应该有一个名称

也许可以尝试

#define EXPORT_IT __declspec( dllexport )

namespace ConnectHttps
{
    class EXPORT_IT ConnectMe
    {
        void GetUrl(char *url, unsigned int bufferLength);
    };
}

此外,我也不能 100% 确定这一点,因为我目前无法访问编译器,但输入:

namespace ConnectHttps {
    ...
}

您的 .cpp 文件中的内容不正确。相反,你应该:

void ConnectHttps::ConnectMe::GetUrl(char* url, unsigned bufferLength)
{
    MyConnectionClass initSec;
    string response = initSec.GetResult();
    strncpy_s(url, bufferLength, response.c_str(), response.length());
}

Unless I'm mistaken, you don't seem to be giving your class a name.
You made ConnectMe not a class name but a macro to export your class, but your class should have a name

Maybe try

#define EXPORT_IT __declspec( dllexport )

namespace ConnectHttps
{
    class EXPORT_IT ConnectMe
    {
        void GetUrl(char *url, unsigned int bufferLength);
    };
}

Also I'm not 100% sure of this because I don't have access to a compiler at the moment, but typing:

namespace ConnectHttps {
    ...
}

In your .cpp file isn't correct. Instead you should have:

void ConnectHttps::ConnectMe::GetUrl(char* url, unsigned bufferLength)
{
    MyConnectionClass initSec;
    string response = initSec.GetResult();
    strncpy_s(url, bufferLength, response.c_str(), response.length());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文