-1

I have a Structure :-

Test.h

typedef struct employees
{
    char* name[5];
    int empi_id;
};

Test.cpp I created a function where I need store the values within these structure.

int Disp()
{
    employees e[5];
    e[0].empi_id=10;
    e[1].empi_id=100;
    e[2].empi_id=500;
    e[3].empi_id=1000;
    e[4].empi_id=5000;
    return 0;
}

TestDll.cpp Console Application:

void main()
{
    LoadLibrary(("TestDll.dll"));

    int obj = Disp();
}

I need to return these array of structure to my Console Application.I want to display the assigned values in my Console Application directly.How Should I return it?Can I send these array of structure as a function parameter then how should I do it.Since I need to send an array of 5. Checking out the below link did gave me an idea of assigning the values to the structure but I cant display the values in my Console App. return an array of structs or an array of struct pointers?

Community
  • 1
  • 1
TechBrkTru
  • 346
  • 1
  • 25

1 Answers1

1

Change function signature in to

int Disp(employees *) ;

it' OK. What is not ok is how you link your DLL. You can either loat it at startup (it happens behind the scenes) or with LoadLibray, but this requires a GetProcAddress too. First way it's easier. It allows you to load a DLL as if it were a library.

marom
  • 5,064
  • 10
  • 14
  • @ marom : so if i use the structure as function parameter ,can i display all the values stored at different index ie for(int i =0;i<5;i++){ e[i].empi_id int::Parse(Console::ReadLine())} ????? – TechBrkTru May 27 '15 at 05:20
  • :I have a problem in accessing the name ?? @marom – TechBrkTru Jun 01 '15 at 13:24
  • accessing th variable "name" @marom – TechBrkTru Jun 02 '15 at 04:11
  • Well the dll must know the definition of struct employees. But declaration of name looks wrong, I would expect char name[], not char *name[] that declares an array of pointers to char. – marom Jun 02 '15 at 05:45
  • I require five employees names ,Since char array stores single character I used them .I need to pass this structure to C# .If I just use char name[] ,can I pass this structure to C#??? @marom – TechBrkTru Jun 02 '15 at 06:34
  • Further help can be found here http://stackoverflow.com/questions/30028593/const-char-in-c – marom Jun 02 '15 at 06:41