Click here to Skip to main content
13,145,464 members (49,403 online)
Rate this:
Please Sign up or sign in to vote.
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.

#pragma once
#define DAILY_PERIOD 24*60
#define MIN_PERIOD 1
#ifdef API_DLL 
#define METHOD_TYPE __declspec(dllexport)
#define METHOD_TYPE __declspec(dllimport)
struct Quote {
unsigned long Date;
float Price;
float Open;
float High;
float Low;
float Volume;
float OpenInterest; 
class METHOD_TYPE CMinuteApiCallback
virtual int quote_notify( const char* symbol, int interval, int nMaxSize, Quotation *pQuotes, unsigned long echo)=0;

class METHOD_TYPE CMinuteApi
int Initialise(char *serialkey, CMinuteApiCallback* callback);
int GetQuote(char * symbol, int periodicity, unsigned long lasttimeupdate, unsigned long echo);
int DeleteQuote(char * symbol, int periodicity);

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 14-Jan-13 6:48am
Updated 14-Jan-13 6:49am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

please follow that link DLLIMPORT

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Rate this: bad
Please Sign up or sign in to vote.

Solution 4

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100