Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am totally new in C++ and I want to use C++ dll (having header file) in C# program.

Please find below header file.

C#
#pragma once
#define DAILY_PERIOD 24*60
#define MIN_PERIOD 1

#ifdef API_DLL 
#define METHOD_TYPE __declspec(dllexport)
#else
#define METHOD_TYPE __declspec(dllimport)
#endif

struct Quote {
unsigned long Date;
float Price;
float Open;
float High;
float Low;
float Volume;
float OpenInterest; 
};

class METHOD_TYPE CMinuteApiCallback
{
public: 

virtual int quote_notify( const char* symbol, int interval, int nMaxSize, Quotation *pQuotes, unsigned long echo)=0;

};


class METHOD_TYPE CMinuteApi
{
public:
CMinuteApi(void);

int Initialise(char *serialkey, CMinuteApiCallback* callback);

int GetQuote(char * symbol, int periodicity, unsigned long lasttimeupdate, unsigned long echo);

int DeleteQuote(char * symbol, int periodicity);

~CMinuteApi(void);
};


So please let me know how can I call all these methods in my C# program.

Thanks in advance.

[Edit]Code block added[/Edit]
Posted
Updated 14-Jan-13 6:49am
v2

You can use the the Dllimport to use functions in your C++ dll files,

please follow that link DLLIMPORT

Regards...
 
Share this answer
 
 
Share this answer
 
If you are new to C++, then it might not the best idea to make a program that use both languages.

Also your C++ code does not use the same charset as the C# one so it might be problematic for internationalization.

Also your declaration have many problems in the context of being used from C# starting with constructor and destructor and also with inconsistent usage of const modifier. In particular, you would have to modify the interface so that the allocation of memory would be done by the C++ DLL. Same for calling destructor and freeing memory at the end.

I think it would be best to implement everything in C# for simplicity purpose.

If you really need some C++ code (for example to reuse existing code that would require more than a few hours to port), the using mixed mode C++ (C++/CLI in default mode: /clr) for an intermediate DLL might be the easiest route... but you still have some advanced stuff to learn like using gc_root.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900