VisualC ++ DLL中的OpenSSL [英] OpenSSL in a VisualC++ DLL

查看:111
本文介绍了VisualC ++ DLL中的OpenSSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i'm trying to write a C++ DLL which uses openSSL to secure a connection to a server.

我对此代码感到困惑,

#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中崩溃. 这是我的例外:

works fine in a Console application, but crashes in my DLL. Here's my exception:

在TestsForPKCSDLL.exe中的0x00007FF865207DA0(libeay32.dll)处引发的异常:0xC0000005:访问冲突读取位置0x0000000000000000.

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

非常感谢您的时间.

推荐答案

经过一些研究,看来问题出在htonl()函数上.

After a bit of research, it looks like the problem comes from the htonl() function.

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

在TestsForPKCSDLL.exe中的0x00007FF863807DA0(libeay32.dll)处引发的异常:0xC0000005:访问冲突读取位置0x0000000000000000.

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

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

Which apparently is not loaded properly. I think that, because my code is in a DLL, it crashes if the calling program doesn't reference SSL dlls. I'll try to link libeay32 and ssleay32 statically see if that works.

这篇关于VisualC ++ DLL中的OpenSSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆