Hey all,
I'm trying to export some of my functions to dll and im having some trouble.
how i created my dll and lib:
my def file:
my c file:
The function "adde" works fine so im guessing the dll is ok but "Refresh" has a problem.
i don't know if
isn't being executed or that nothing is being returned to "t".
For some reason i can't debug it , as if the code stops at the line
I can debug before that line but if for example i add this line:
after
I won't see the popup.
Thanks
I'm trying to export some of my functions to dll and im having some trouble.
how i created my dll and lib:
Code:
// Define DllExport to declare exported symbols.
#define DllExport __declspec( dllexport )
DllExport __declspec( dllexport )
#include <stdio.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <commctrl.h>
typedef struct
{
char secnum[8];
char xnum[8];
char xfirst[10];
char xlast[10];
char xage[3];
char xaddress[10];
char xphone[10];
}Item;
typedef struct phonebook
{
char num[4];
char first_name[10];
char last_name[10];
char age[3];
char address[10];
char phone[10];
} PB;
DllExport int adde (int x, int y)
{
return (x+y);
}
DllExport int Refresh(FILE *f1,Item ListItem[])
{
char str2[4];
int x=0,y=1;
PB p;
rewind(f1);
while (fread(&p, sizeof(PB), 1, f1))
{
itoa (y,str2,10);
strcpy(ListItem[x].secnum,p.num);
strcpy(ListItem[x].xnum,str2);
strcpy(ListItem[x].xfirst,p.first_name);
strcpy(ListItem[x].xlast,p.last_name);
strcpy(ListItem[x].xage,p.age);
strcpy(ListItem[x].xaddress,p.address);
strcpy(ListItem[x].xphone,p.phone);
x++;
y++;
}
return x;
}
my def file:
Code:
EXPORTS
adde
Refresh
my c file:
Code:
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
......
int t=-1;
typedef int (CALLBACK *MYPROC)(int);
typedef int (CALLBACK *MYPROC2)(FILE*, Item*);
HINSTANCE hinstLib;
MYPROC ProcAdd;
MYPROC2 ProcAdd2;
int fRunTimeLinkSuccess;
....
}
case WM_COMMAND :
.......
hinstLib = LoadLibrary("MyProj.dll");
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "adde");
if (fRunTimeLinkSuccess = (ProcAdd != NULL))
bla = ProcAdd (4,4); // Works! bla is now 8
FreeLibrary(hinstLib);
.......
hinstLib = LoadLibrary("MyProj.dll");
if (hinstLib != NULL)
{
ProcAdd2 = (MYPROC2) GetProcAddress(hinstLib, "Refresh");
if (fRunTimeLinkSuccess = (ProcAdd2 != NULL))
t=ProcAdd2 (poi,ListItem); // Doesn't work
FreeLibrary(hinstLib);
}
The function "adde" works fine so im guessing the dll is ok but "Refresh" has a problem.
i don't know if
Code:
t=ProcAdd2 (poi,ListItem);
For some reason i can't debug it , as if the code stops at the line
Code:
t=ProcAdd2 (poi,ListItem)
I can debug before that line but if for example i add this line:
Code:
MessageBox(hwnd, "Test", "Test", MB_OK);
Code:
t=ProcAdd2 (poi,ListItem);
Thanks