Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Help with exporting to a dll (http://www.go4expert.com/forums/help-exporting-dll-t20680/)

Shasoosh 16Jan2010 14:42

Help with exporting to a dll
 
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:

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);
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
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);
after
Code:

t=ProcAdd2 (poi,ListItem);
I won't see the popup.

Thanks


All times are GMT +5.5. The time now is 12:46.