Hi
My current editor is Dev-Cpp 4.9.2.2 .My test program which runs fine looks like
dll.h

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C"
{
 #endif
  __declspec(dllexport) void HelloWorld();
#ifdef __cplusplus
}
#endif

And dll.cpp

#include"dll.h"

void HelloWorld ()
{
    MessageBox (0, "This is a sample application!\n", "Hi", MB_ICONINFORMATION);
}

This code runs fine. Now i tried the same thing with my program where i'm using boostlib.
so my dll.h changed to

/*List of header files */

using namespace boost;
using namespace std;    
   
//Contains vertex properties of a graph
struct Vertex_Prop 
{
    string name;
 };

//Contains edge properties of a graph
struct Edge_Prop
{
    int weight;
 };           

typedef graph_traits <adjacency_list<> >::vertex_descriptor Vertex;
struct Graph_Prop
{
   std::map<string,Vertex> nodes;
};

typedef adjacency_list <setS, vecS, bidirectionalS, Vertex_Prop, \
        Edge_Prop,Graph_Prop > Graph;

[B]#ifdef __cplusplus
extern "C"
{
  #endif
    __declspec(dllexport) int CreateGraph(Graph &g);
#ifdef __cplusplus
}
#endif
[/B]

This code gives a linking error. Even if you are not well versed with boost i just want to know what is the correct way to write code for bold part if i want to create a dll of this. The above code is running fine when i have created exe or a console application for this. Where in the header i have simply declared the function without any __declspec(dllexport).
Kindly help

There is no "bold part". Please refer to the line numbers of the code you posted.

The way I create and use DLLs is to use a macro to determine whether to use __dllimport or __dllexport

#ifdef MYDLL
#define MYAPI __declspec(__dllexport)
#else
#define MYAPI __declspec(__dllexport)
#endif

MYAPI void HelloWorld();

If you put the above in the .h file you can include it in both the DLL and application project. In the DLL project just declare MYDLL

The bold part i'm talking about is from line no. 27-35 the solution provided in which macros need to be defined in the .h files can i remove the extern C as well.

>>can i remove the extern C as well.
No, leave that as it is since you want to use the DLL with C code. If you're going to only use it with C++ then you don't need it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.