我正在尝试编写一个 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/