I have a DLL
A.dll
This is A.h
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
#define DLL_EXPORT extern "C" __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllexport)
#endif
DLL_EXPORT void function();
DLL_EXPORT char ** ReturnArr;
This is A.c
void function()
{
char *str = "hello";
char *str1 = "how are you?";
ReturnArr = (char **)malloc(sizeof(char*) * 2);
for(;j<2;j++)
{
ReturnArr[j] = (char *) malloc(256);
if(NULL == ReturnArr[j])
break;
}
strcpy(ReturnArr[0],"str");
strcpy(ReturnArr[1],"str1");
}
Now i have Application.c that would use dll
#include <windows.h>
#include <stdio.h>
typedef int (__cdecl *MYPROC)(LPWSTR);
_declspec(dllimport) char ** ReturnArr;
int main( void )
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
int a = 0;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
hinstLib = LoadLibrary(TEXT("A.dll"));
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "function");
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (L"Message sent to the DLL function\n");
printf("%s",Returnarr[0]);
}
fFreeResult = FreeLibrary(hinstLib);
}
if (! fRunTimeLinkSuccess)
printf("Message printed from executable\n");
return 0;
}
##In Visual studio CommonProperties->references:i added A.dll its showing me compiler error
Error 1 error LNK2001: unresolved external symbol "__declspec(dllimport) char ** ReturnArr" (__imp_?ReturnArr@@3PAPADA)"
and
Error 2 fatal error LNK1120: 1 unresolved ##externals
tell me a way how can i actually print ReturnArr as a global variable in my application
thanks