c++ - VisualC++ DLL 中的 OpenSSL

标签 c++ dll openssl winsock winsock2

我正在尝试编写一个 C++ DLL,它使用 openSSL 来保护与服务器的连接。

我真的很困惑这个代码

#include "stdafx.h"
#include <string.h>
#include <iostream>
//SSL stuff
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/x509.h>
#include <openssl/x509_vfy.h>
#include <openssl/ossl_typ.h>
#include <openssl/applink.c>
//Winsock stuf
#pragma comment(lib, "ws2_32.lib")
{... Create a method in which we set up the SSL connection ...}
char* tSend = "{\"reqtype\":\"keyexchange\"}";
int sendSize = strlen(tSend);
int net_tSend = htonl(sendSize);
SSL_write(ssl, &net_tSend, 4);
SSL_write(ssl, tSend, sendSize);

在控制台应用程序中工作正常,但在我的 DLL 中崩溃。 这是我的异常(exception):

Exception thrown at 0x00007FF865207DA0 (libeay32.dll) in TestsForPKCSDLL.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

非常感谢您的宝贵时间。

最佳答案

经过一些研究,问题似乎出在 htonl() 函数上。

    u_long mylong = 10L;
    int net_tSend = htonl(mylong);

Exception thrown at 0x00007FF863807DA0 (libeay32.dll) in TestsForPKCSDLL.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

显然没有正确加载。我认为,因为我的代码在 DLL 中,如果调用程序不引用 SSL dll,它就会崩溃。我将尝试静态链接 libeay32 和 ssleay32,看看是否可行。

关于c++ - VisualC++ DLL 中的 OpenSSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36704926/

相关文章:

c++ - 为什么在没有返回类型的情况下显式调用构造函数时会返回一个临时对象?

windows - 如何在使用 Visual C++ 2010 命令提示符时包含/链接 DLL

c++ - GCC 标准库 XCode 4.5

php - 如何解决错误 : Need OpenSSL support for https://requests?

c++ - 将派生自基类的类的实例传递给函数

c++ - 如何从 2D initializer_list 中读取值并将它们放入 2D vector 中

java - 无法通过 Java 在 MATLAB 中加载 DLL

php - 使用 openssl : recompile with -fPIC 编译 PHP 时出错

ssl - 如何从多个文件创建可用的证书存储

c++ - 在 C++ 并行 PRNG 领域取得领先