Hi everybody!
I'm a newbie with C development, so have patience with me... ^^
Well... I´m building a DLL that calls another DLL (a DLL Wrapper to solve JNI problems... or better to say Oracle Webutil problems... but this don´t matter at this moment).
The problem occours when the method of target DLL is called. I got a Access Violation on MSVCRT.DLL. I believe that's some mistake on parameters passage or anywhere around it.
Please, a little help here... I promisse learn more about C language when I´ve more time (and improve my english too ^^).
The wrapper DLL code:
(wPCLink6.h)
Code:
#ifndef _wPCLINK6_H_
#define _wPCLINK6_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
DLLIMPORT void Display_Erro(int Ip_Setado, char * Message);
#endif /* _wPCLINK6_H_ */
(wPCLink6.c)
Code:
#include "wPCLink6.h"
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
typedef char * (__cdecl *Display_ErroFn)(int Ip_Setado);
DLLIMPORT void Display_Erro(int Ip_Setado, char *Message)
{
DWORD Error = 0;
HINSTANCE libInst = LoadLibrary("pclink6.dll");
if (!libInst)
{
Error = GetLastError();
sprintf(Message, "Error: %d", Error);
return;
}
Display_ErroFn Display_ErroHnd = (Display_ErroFn)GetProcAddress(libInst, "Display_Erro");
if (Display_ErroHnd == 0)
{
Error = GetLastError();
sprintf(Message, "Error: %d", Error);
return;
}
Message = Display_ErroHnd(const Ip_Setado); // Crash happens
sprintf(Message, "I´m here!"); // Unreachable code
FreeLibrary(libInst);
return;
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
Target DLL Code:
(PCLink6.h)
Code:
#ifndef _PCLINK6_H_
#define _PCLINK6_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
DLLIMPORT char * Display_Erro(int Ip_Setado);
#endif /* _PCLINK6_H_ */
(PCLink6.c)
Code:
#include "teste.h"
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
char * Message;
DLLIMPORT char * Display_Erro(int Ip_Setado)
{
strcpy(Message,"Sucess!");
return Message;
return 0;
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
Note that my only desire is recive "Sucess!" string through Message parameter.