【发布时间】:2016-04-18 21:50:37
【问题描述】:
我正在尝试编写一个 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 中崩溃。 这是我的例外:
TestsForPKCSDLL.exe 中的 0x00007FF865207DA0 (libeay32.dll) 引发异常:0xC0000005:访问冲突读取位置 0x0000000000000000。
非常感谢您的宝贵时间。
【问题讨论】:
-
调试器告诉你什么?
-
访问接近 0 的地址时发生 AccessViolation 意味着正在访问 NULL 指针。在代码中找到 NULL 指针并修复它。最有可能的罪魁祸首是您的
ssl指针,或者链接到的SSL_CTX或BIO。 -
这个问题到底是什么(除了你很困惑之外)?
-
@Dan:我引用的消息(抛出异常......)。
-
@jww:好吧,当然是如何让它工作了。
标签: c++ dll openssl winsock winsock2