gpt4 book ai didi

c - GNU C 编程 : getting error (Segmentation fault (core dumped)) when calling another c dll function

转载 作者:行者123 更新时间:2023-11-30 21:49:06 24 4
gpt4 key购买 nike

#include <stdio.h>;
#include <windows.h>;
#include <malloc.h>;
typedef int (__cdecl *MYPROC)( void *epcs, char *message, char *sign,unsigned int *sig_len );
main();
{
HINSTANCE hh;
MYPROC hhLib;
void *j;
int *x = (int*)malloc(8);
unsigned int *y = (unsigned int*)malloc(8);
int *z = (int*)malloc(8);
char *msg, *sign ;
msg = (char*)malloc(512*sizeof(char));
sign = (char*)malloc(512*sizeof(char));
*x = 2541;
*y = 10;
*z = 0;
j = (int*)*x;
msg = "Test of MSG";
sign = "Test of Sign";
hh = LoadLibrary("epcs.dll");
if (hh == NULL) {
printf("Unable to load epcs shared library\n");
return 0;
}
hhLib = (MYPROC)GetProcAddress(hh, "epcs_test");
if (hhLib==NULL) {
printf("Unable to point shared library function (epcs_test).. \n");
return 0;
}
z = hhLib(j, msg, sign, y);
printf("%d \n",*x);
printf("%d \n",j);
printf("%d \n",*y);
printf("%d \n",*z);
printf("%s \n",msg);
printf("%s \n",sign);
return 0;
}

最佳答案

问题之一在于:

msg = (char*)malloc(512*sizeof(char));  
sign = (char*)malloc(512*sizeof(char));
...
msg = "Test of MSG";
sign = "Test of Sign";

关于c - GNU C 编程 : getting error (Segmentation fault (core dumped)) when calling another c dll function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18513911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com