NO

Author Topic: Exporting a structure from a DLL  (Read 5782 times)

Grincheux

  • Guest
Exporting a structure from a DLL
« on: July 23, 2021, 11:55:00 AM »
Hello,

I have tab of  structure of 60 000 stuctures. The compiler gets an error wile linking.
I decided to put the datas into a dll and export them.
I cannot set the address of the tab into a function and return it.
Later I will crate AddIns like this, or perhaps JohnZ he his the King of the AddIns!

Code: [Select]
typedef   unsigned long long QWORD ;

#define   MAX_EDIT_ROWS            29
#define   MAX_EDIT_COLUMNS         29
#define   MAX_EDIT_FIELDS            MAX_EDIT_ROWS * MAX_EDIT_COLUMNS

#define   MAX_FILTER_NAME_LENGTH      12

#define   GREY_NONE               0
#define GREY_INPUT               1
#define   GREY_OUTPUT               2

#define   FILTER_TYPE_NORMAL         1
#define   FILTER_TYPE_MINIMUM         2
#define   FILTER_TYPE_MAXIMUM         3
#define   FILTER_TYPE_AVERAGE         4
#define   FILTER_TYPE_MEDIAN         5
#define   FILTER_TYPE_DISTANCE      6
#define   FILTER_TYPE_VARIANCE      7
#define   FILTER_TYPE_THRESHOLD      8

#define   NEGATIVE_NO               0
#define   NEGATIVE_YES            1

#define   FUSION_NONE               0

#define   APPLY_DIVISOR_NO         0
#define   APPLY_DIVISOR_YES         1

#define   MODEL_NO               0
#define   MODEL_YES               1

typedef   struct tagCNV_FILTERS
{
   char         Name[MAX_FILTER_NAME_LENGTH + 1] ;
   int            ColsNumber ;
   int            FilterType ;
   int            Divisor ;
   int            Bias ;
   int            Negative ;
   int            Grey ;
   int            Matrix[MAX_EDIT_FIELDS] ;
} CNV_FILTERS, *LPCNV_FILTERS ;

typedef   struct tagPGM_FILTERS
{
   int            RecordNumber ;
   int            TotalNumberOfColumns ;
   int            ApplyTheDivisor ;
   int            Model ;
   int            Fusion ;
   DWORD         Crc64Low ;
   DWORD         Crc64High ;

   CNV_FILTERS      Filter ;
} PGM_FILTERS, *LPPGM_FILTERS ;

#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

PGM_FILTERS   AllTheFilters[]   =      {
{1,9,0,1,0,634056713,115228569,"Filter 00001 - 3",3,1,0,0,0,0,-710,-143,327,135,475,77,-296,-355,471},
{2,9,0,1,0,308491901,911315395,"Filter 00002 - 3",3,1,0,0,0,1,-605,387,-367,260,801,-282,7,-650,456},
{3,9,0,1,0,1462181566,716563056,"Filter 0003 - 3",3,1,0,0,0,0,-504,-527,788,151,-97,112,-560,157,356},
{4,9,0,1,1,632117505,3613146495,"Filter 0004 - 3",3,1,0,0,0,3,-442,79,-351,-327,121,9,561,400,58},
{5,9,0,1,3,1016485661,2892954712,"Filter 0005 - 3",3,1,0,0,0,3,-354,657,424,-116,-504,170,172,-291,-193},
{6,9,0,1,0,1762082927,3464765944,"Filter 0006 - 3",3,1,0,0,0,0,-330,-331,728,-649,684,450,494,-269,-796},
{7,9,0,1,0,4226647309,3205345883,"Filter 0007 - 3",3,1,0,0,0,0,-313,-3,-408,416,557,-248,797,-591,-230},
{8,9,0,1,0,2722049741,3204523318,"Filter 0008 - 3",3,6,0,0,0,1,-301,114,615,-619,-466,-782,-365,478,10},
{9,9,0,1,0,2276074563,3981072491,"Filter 0009 - 3",3,4,0,0,0,0,-255,-17,-5,64,-50,189,92,-51,171},
{10,9,0,1,0,4218383764,2903215869,"Filter 00010 - 3",3,1,0,0,0,0,-255,54,238,-247,73,183,-134,-63,239},
{11,9,0,1,0,2075610727,3783828473,"Filter 00011 - 3",3,1,0,0,0,0,-254,-166,-105,226,96,-20,-1,94,136},
{12,9,0,1,0,3511955899,3001072808,"Filter 00012 - 3",3,1,0,0,0,0,-254,-138,-50,96,-33,248,10,191,-52},
{13,9,0,1,0,2857026654,2288975881,"Filter 00013 - 3",3,4,0,0,0,0,-254,108,248,220,142,-237,186,-123,-247},
{   0,  0,0,0,0,0,0,"(None)",0,1,0,0,0,0}
} ;

How to declare it ?
Do I have to put it into a DEF file ?

Thank Your for your help.
« Last Edit: July 23, 2021, 03:49:30 PM by Grincheux »

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Exporting a structure from a DLL
« Reply #1 on: July 23, 2021, 02:31:37 PM »
Well that is just mind boggling! 

I am not an expert at this, and very little practical experience creating dll's …..but

I believe you need to put it into a procedure then export that procedure using a DEF file or using __declspec(dllexport) keyword so you can call it, from your main program to load your 60,000 array.

John Z

PS what is the compiler error?  Maybe it can be mitigated by breaking the array creation into two or more smaller .h files?

Grincheux

  • Guest
Re: Exporting a structure from a DLL
« Reply #2 on: July 23, 2021, 06:11:56 PM »
I made other sillies DLL, there is one the compiler takes 24 hours to create it!

To declare the variable for export use "EXTFILTERAPI PGM_FILTERS   AllTheFilters[]   =      {"

I will try with to educe the size of fields, use char rather than int.
One INT is equal to FOUR CHARs.
Like this, it is like I had 60 000 / 4 = 15 000 structures!

I hope

The compiler crash with an internal error.

Quote
Building dllmain.obj.
Building Filtres.obj.
Building ExtFilters.dll.
Creating object: C:\Users\51966\Documents\Pelles C Projects\Cfe\ExtFilters\ExtFilters.exp
Creating library: C:\Users\51966\Documents\Pelles C Projects\Cfe\ExtFilters\ExtFilters.lib
POLINK: fatal error: Internal error: write_executable_image().
*** Error code: 1 ***
Done.


I use the last Pelle's C version (V11), the problem was the same with the previous version.

« Last Edit: July 23, 2021, 06:13:57 PM by Grincheux »

Grincheux

  • Guest
Re: Exporting a structure from a DLL
« Reply #3 on: July 23, 2021, 06:27:00 PM »
If I change the structure like this:

Code: [Select]
typedef   struct tagCNV_FILTERS
{
   char         Name[MAX_FILTER_NAME_LENGTH + 1] ;
   short         ColsNumber ;
   char         FilterType ;
   short         Divisor ;
   short         Bias ;
   char         Negative ;
   char         Grey ;
   short         Matrix[MAX_EDIT_FIELDS] ;
} CNV_FILTERS, *LPCNV_FILTERS ;

typedef   struct tagPGM_FILTERS
{
   int            RecordNumber ;
   short         TotalNumberOfColumns ;
   char         ApplyTheDivisor ;
   char         Model ;
   char         Fusion ;
//   char         Crc64Low ;
//   char         Crc64High ;

   CNV_FILTERS      Filter ;
} PGM_FILTERS, *LPPGM_FILTERS ;
Quote
Building Filtres.obj.
Building ExtFilters.dll.
Creating object: C:\Users\51966\Documents\Pelles C Projects\Cfe\ExtFilters\ExtFilters.exp
Creating library: C:\Users\51966\Documents\Pelles C Projects\Cfe\ExtFilters\ExtFilters.lib
Done.









Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Exporting a structure from a DLL
« Reply #4 on: July 23, 2021, 06:38:19 PM »
The current linker limit for output files is 128 MB. This can be increased, but I'm not sure it's very common or useful to create multi-megabyte files.
At least distribution will be a bit of a pain...
/Pelle