Click here to Skip to main content
Sign Up to vote bad
good
See more: C++C#
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)
#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 14 Jan '13 - 6:48
Edited 14 Jan '13 - 6:49
ProgramFOX56.4K


3 solutions

You can use the the Dllimport to use functions in your C++ dll files,
 
please follow that link DLLIMPORT
 
Regards...
  Permalink  
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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 146
1 Richard MacCutchan 145
2 Sergey Alexandrovich Kryukov 134
3 Tadit Dash 134
4 Santhosh G_ 120
0 Sergey Alexandrovich Kryukov 10,348
1 OriginalGriff 7,965
2 CPallini 4,241
3 Rohan Leuva 3,522
4 Maciej Los 3,184


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid