NO

Author Topic: write my own dll using MS VC++ template  (Read 4345 times)

Feierabend

  • Guest
write my own dll using MS VC++ template
« on: April 08, 2008, 10:06:45 AM »
Hello,
I am new to Pelles C.

I have deep experiences with C under Unix plattforms,
but none with C under Win32.

Actually I try to create a dll file which shall contain a function mytest()
I'd like to call from several different exe files.
To do this I've got a Demo.h template which looks like this:


#ifndef DEMO_H
#define DEMO_H

typedef char bool;
struct DEMO_DATASTRUCT
{
    int year,month,day,starttime,endtime;
    bool plotme;
    bool ascii_been_here;
};

extern "C" double __declspec(dllexport) mytest(DEMO_DATASTRUCT *price_ptr,
    int currentptr, int *int_args, int num_int_args, double *double_args,
    int num_double_args, char **string_args, int num_string_args);

#endif

The according c-source Demo.c file has this content:

#include <windows.h>
#include "Demo.h"

//---------------------------------------------------------------------------

extern "C" double __declspec(dllexport) mytest(DEMO_DATASTRUCT *price_ptr,
    int currentptr, int *int_args, int num_int_args, double *double_args,
    int num_double_args, char **string_args, int num_string_args)
{
    /* well, this function actually does nothing usefull,
    however, it should compile without failure */
   
    return 0.4711;
}

#pragma argsused
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
    return 1;
}


My question regarding Pelles C is,
how must this template be modified to compile it as a dll library.

I'd appreciate, if anyone could explain me this.

Thanks in advance
Christoph
« Last Edit: April 08, 2008, 10:10:43 AM by Feierabend »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: write my own dll using MS VC++ template
« Reply #1 on: April 08, 2008, 08:04:42 PM »
For example:
Demo.h
Code: [Select]
#ifndef DEMO_H
#define DEMO_H

typedef char bool;
typedef struct tagDEMO_DATASTRUCT
{
    int year,month,day,starttime,endtime;
    bool plotme;
    bool ascii_been_here;
} DEMO_DATASTRUCT;

#ifdef __cplusplus
extern "C"
{
#endif
double __declspec(dllexport) mytest(DEMO_DATASTRUCT *price_ptr,
    int currentptr, int *int_args, int num_int_args, double *double_args,
    int num_double_args, char **string_args, int num_string_args);
#ifdef __cplusplus
}
#endif
#endif
Demo.c
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "Demo.h"

//---------------------------------------------------------------------------

double __declspec(dllexport) mytest(DEMO_DATASTRUCT *price_ptr,
    int currentptr, int *int_args, int num_int_args, double *double_args,
    int num_double_args, char **string_args, int num_string_args)
{
    /* well, this function actually does nothing usefull,
    however, it should compile without failure */
   
    return 0.4711;
}

#pragma argsused
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
    return 1;
}
May the source be with you

Feierabend

  • Guest
Re: write my own dll using MS VC++ template
« Reply #2 on: April 09, 2008, 06:47:08 AM »
Thank you very much.

The compiler also creates
C:\Programme\PellesC\Projects\demo\demo.exp
C:\Programme\PellesC\Projects\demo\demo.lib

What are these files good for?

Feierabend

  • Guest
Re: write my own dll using MS VC++ template
« Reply #3 on: April 09, 2008, 09:56:57 AM »
And another question, please, too:

if I want to access a function residing in an other already finished dll,
how do I have to declare it within my Demo.c ?

I have a swe32.dll which has a function built in
which is called swe_date_conversion() for instance.

The function is defined as

Code: [Select]
int swe_date_conversion(
    int yyyy, int month, int day,
    double hour,
    double *tjd);

I want to call it in function mytest() as coded in Demo.c

Now mytest() looks like:

Code: [Select]
double __declspec(dllexport) mytest(DEMO_DATASTRUCT *price_ptr,
    int currentptr, int *int_args, int num_int_args, double *double_args,
    int num_double_args, char **string_args, int num_string_args)
{

    double tjd = 0.0;
    int vdate = swe_date_conversion(2008, 4, 9, 12.0, &tjd);

    return tjd;

}

Actually I get "POLINK: error: Unresolved external symbol '__imp__swe_date_conversion'."
I thinks it's a matter of declaration here.

Please can you show me how to declare the swe_date_conversion() correctly?

« Last Edit: April 09, 2008, 10:06:10 AM by Feierabend »

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: write my own dll using MS VC++ template
« Reply #4 on: April 09, 2008, 01:10:16 PM »
Actually I get "POLINK: error: Unresolved external symbol '__imp__swe_date_conversion'."
I thinks it's a matter of declaration here.

Please can you show me how to declare the swe_date_conversion() correctly?
Include the swe32.lib in the Linker options of the Project options for your project.
---
Stefan

Proud member of the UltraDefrag Development Team