Adaptation C++ au C
foobar47
-
pac -
pac -
Bonjour à toutes et à tous,
j'aurais aimé que vous m'aidiez à faire le lien entre le langage C++ et le C.
Cela eut paraitre idiot, mais je n'y arrive pas.
Je possède les sources du C++ que voila:
#include "stdafx.h"
#include "SDKExample.h"
#include "SDKExampleDoc.h"
#include "SDKExampleView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSDKExampleView
#define DLLIMPORT extern "C" __declspec(dllimport)
#define FUNCTIONFLAGS __stdcall
DLLIMPORT int FUNCTIONFLAGS cviTestCard (short DeviceNumber, short nBoardType, short nGain);
DLLIMPORT int FUNCTIONFLAGS cviSetIntEx(int const nBase, int const nPixelNumber, long const lTime, int nDeviceNumber, int nChannel, int nGain);
DLLIMPORT int FUNCTIONFLAGS cviSetInt(int const nTriggerMode, long const lTime);
DLLIMPORT int FUNCTIONFLAGS cviTriggerReadEx(int const nBase, long const lTime, int const nUnitType, USHORT* pArray);
DLLIMPORT int FUNCTIONFLAGS cviCloseEx();
DLLIMPORT void FUNCTIONFLAGS cviPolyCalc(double *coefs, int order, int x, double *y);
DLLIMPORT int FUNCTIONFLAGS cviPolyFit(double *x, double *y, int numPts,double *coefs, int order);
IMPLEMENT_DYNCREATE(CSDKExampleView, CView)
BEGIN_MESSAGE_MAP(CSDKExampleView, CView)
//{{AFX_MSG_MAP(CSDKExampleView)
ON_COMMAND(IDM_GETDATA, OnGetdata)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW,View::OnFilePrintPreview)
END_MESSAGE_MAP()
//////////////////////////////////////////////////// //CSDKExampleView construction/destruction
CSDKExampleView::CSDKExampleView()
{
// TODO: add construction code here
m_nSite=0;
}
CSDKExampleView::~CSDKExampleView()
{
}
BOOL CSDKExampleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
//////////////////////////////////////////////////////
// CSDKExampleView drawing
void CSDKExampleView::OnDraw(CDC* pDC)
{
CSDKExampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
//////////////////////////////////////////////////////
// CSDKExampleView printing
BOOL CSDKExampleView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSDKExampleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSDKExampleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
//////////////////////////////////////////////////////
// CSDKExampleView diagnostics
#ifdef _DEBUG
void CSDKExampleView::AssertValid() const
{
CView::AssertValid();
}
void CSDKExampleView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSDKExampleDoc* CSDKExampleView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSDKExampleDoc)));
return (CSDKExampleDoc*)m_pDocument;
}
#endif //_DEBUG
//////////////////////////////////////////////////////
// CSDKExampleView message handlers
void CSDKExampleView::OnGetdata()
{
// TODO: Add your command handler code here
CClientDC dc(this);
USHORT *PixArray; //for pixel data
long lIntTime=11; //the least integration time is 11ms for 6023, and 35ms for 1200
int nPixelNo = 2086; //for Sony CCD
int nRwturnValue = cviTestCard(1, 1, 2);//DeviceNumber = 1; Board = 6023; Gain = 2;
if(nRwturnValue<0) //fail to test the board
{
AfxMessageBox("The NI board does not work correctly.");
return;
}
else dc.TextOut(0,m_nSite,"Testing the NI board... OK!");
cviSetIntEx(0x300, 2086, lIntTime, 1,0, 2);// Initialize the board
dc.TextOut(0,m_nSite + 14,"Initializing the NI board... OK!");
cviSetInt(10, lIntTime);// Freerun trigger mode and set the integration time
dc.TextOut(0,m_nSite + 28,"Setting Integration time... OK!");
PixArray = new USHORT[nPixelNo];//Array for pixel data
dc.TextOut(0,m_nSite + 42,"Starting data acquisition... OK!");
nRwturnValue = cviTriggerReadEx(0x300, lIntTime, 0, PixArray);
if(nRwturnValue!=nPixelNo)
{
AfxMessageBox("Data Aquisition does not work correctly.");
delete[] PixArray;
return;
}
dc.TextOut(0,m_nSite + 56,"Data acquisition has been finished successfully... OK!");
//Calibration for the wavelength
double fWaveLength[14];
double fPixelNo[14];
int CalibrationNo=14;
double fCoefficient[5];
//Reandom calibration data
fWaveLength[0] = 296.7 ; fPixelNo[0] = 34;
fWaveLength[1] = 302.1; fPixelNo[1] = 81;
fWaveLength[2] = 313.2; fPixelNo[2] = 181;
fWaveLength[3] = 365.0; fPixelNo[3] = 226;
fWaveLength[4] = 435.8; fPixelNo[4] = 413;
fWaveLength[5] = 546.1; fPixelNo[5] = 697;
fWaveLength[6] = 577.0; fPixelNo[6] = 775;
fWaveLength[7] = 579.1; fPixelNo[7] = 781;
fWaveLength[8] = 696.5; fPixelNo[8] = 1073;
fWaveLength[9] = 763.5; fPixelNo[9] = 1237;
fWaveLength[10] = 772.4; fPixelNo[10] = 1259;
fWaveLength[11] = 811.5; fPixelNo[11] = 1354;
fWaveLength[12] = 912.3; fPixelNo[12] = 1595;
fWaveLength[13] = 1014.0; fPixelNo[13] = 1835;
cviPolyFit(fPixelNo, fWaveLength, CalibrationNo,fCoefficient, 3);
HFILE file = _lcreat("SMSDK_test.txt",0);
char strTemp[80];
sprintf(strTemp," Pixel Wavelength(nm) Intensity \r\n");
_lwrite(file,(LPSTR)strTemp,strlen(strTemp));
for(int i=32;i<2080;i++)
{
double fWL;
cviPolyCalc(fCoefficient,3,i-31 ,&fWL);
sprintf(strTemp," %5d %5.2f %5d\r\n",i-31,fWL,(int)PixArray[i]);
_lwrite(file,(LPSTR)strTemp,strlen(strTemp));
}
_lclose(file);
dc.TextOut(0,m_nSite + 70,"Data is saved in SMSDK_test.txt ... OK!");
delete[] PixArray;
cviCloseEx(); //Close the board
dc.TextOut(0,m_nSite + 84,"All process for Data acquisition has been completed successfully... OK!");
}
C'est surout la partie en gras qui m'interresse !
Je ne sais pas du tout à quoi correspond la syntaxe "::" et comment interpreter les "Class" !?
Si quelqu'un pouvait m'aider, ou du moins m'expliquer, je lui en serait trés reconnaissant :))
Merci d'avance et bonne journée.
j'aurais aimé que vous m'aidiez à faire le lien entre le langage C++ et le C.
Cela eut paraitre idiot, mais je n'y arrive pas.
Je possède les sources du C++ que voila:
#include "stdafx.h"
#include "SDKExample.h"
#include "SDKExampleDoc.h"
#include "SDKExampleView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSDKExampleView
#define DLLIMPORT extern "C" __declspec(dllimport)
#define FUNCTIONFLAGS __stdcall
DLLIMPORT int FUNCTIONFLAGS cviTestCard (short DeviceNumber, short nBoardType, short nGain);
DLLIMPORT int FUNCTIONFLAGS cviSetIntEx(int const nBase, int const nPixelNumber, long const lTime, int nDeviceNumber, int nChannel, int nGain);
DLLIMPORT int FUNCTIONFLAGS cviSetInt(int const nTriggerMode, long const lTime);
DLLIMPORT int FUNCTIONFLAGS cviTriggerReadEx(int const nBase, long const lTime, int const nUnitType, USHORT* pArray);
DLLIMPORT int FUNCTIONFLAGS cviCloseEx();
DLLIMPORT void FUNCTIONFLAGS cviPolyCalc(double *coefs, int order, int x, double *y);
DLLIMPORT int FUNCTIONFLAGS cviPolyFit(double *x, double *y, int numPts,double *coefs, int order);
IMPLEMENT_DYNCREATE(CSDKExampleView, CView)
BEGIN_MESSAGE_MAP(CSDKExampleView, CView)
//{{AFX_MSG_MAP(CSDKExampleView)
ON_COMMAND(IDM_GETDATA, OnGetdata)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW,View::OnFilePrintPreview)
END_MESSAGE_MAP()
//////////////////////////////////////////////////// //CSDKExampleView construction/destruction
CSDKExampleView::CSDKExampleView()
{
// TODO: add construction code here
m_nSite=0;
}
CSDKExampleView::~CSDKExampleView()
{
}
BOOL CSDKExampleView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
//////////////////////////////////////////////////////
// CSDKExampleView drawing
void CSDKExampleView::OnDraw(CDC* pDC)
{
CSDKExampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
//////////////////////////////////////////////////////
// CSDKExampleView printing
BOOL CSDKExampleView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSDKExampleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSDKExampleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
//////////////////////////////////////////////////////
// CSDKExampleView diagnostics
#ifdef _DEBUG
void CSDKExampleView::AssertValid() const
{
CView::AssertValid();
}
void CSDKExampleView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSDKExampleDoc* CSDKExampleView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSDKExampleDoc)));
return (CSDKExampleDoc*)m_pDocument;
}
#endif //_DEBUG
//////////////////////////////////////////////////////
// CSDKExampleView message handlers
void CSDKExampleView::OnGetdata()
{
// TODO: Add your command handler code here
CClientDC dc(this);
USHORT *PixArray; //for pixel data
long lIntTime=11; //the least integration time is 11ms for 6023, and 35ms for 1200
int nPixelNo = 2086; //for Sony CCD
int nRwturnValue = cviTestCard(1, 1, 2);//DeviceNumber = 1; Board = 6023; Gain = 2;
if(nRwturnValue<0) //fail to test the board
{
AfxMessageBox("The NI board does not work correctly.");
return;
}
else dc.TextOut(0,m_nSite,"Testing the NI board... OK!");
cviSetIntEx(0x300, 2086, lIntTime, 1,0, 2);// Initialize the board
dc.TextOut(0,m_nSite + 14,"Initializing the NI board... OK!");
cviSetInt(10, lIntTime);// Freerun trigger mode and set the integration time
dc.TextOut(0,m_nSite + 28,"Setting Integration time... OK!");
PixArray = new USHORT[nPixelNo];//Array for pixel data
dc.TextOut(0,m_nSite + 42,"Starting data acquisition... OK!");
nRwturnValue = cviTriggerReadEx(0x300, lIntTime, 0, PixArray);
if(nRwturnValue!=nPixelNo)
{
AfxMessageBox("Data Aquisition does not work correctly.");
delete[] PixArray;
return;
}
dc.TextOut(0,m_nSite + 56,"Data acquisition has been finished successfully... OK!");
//Calibration for the wavelength
double fWaveLength[14];
double fPixelNo[14];
int CalibrationNo=14;
double fCoefficient[5];
//Reandom calibration data
fWaveLength[0] = 296.7 ; fPixelNo[0] = 34;
fWaveLength[1] = 302.1; fPixelNo[1] = 81;
fWaveLength[2] = 313.2; fPixelNo[2] = 181;
fWaveLength[3] = 365.0; fPixelNo[3] = 226;
fWaveLength[4] = 435.8; fPixelNo[4] = 413;
fWaveLength[5] = 546.1; fPixelNo[5] = 697;
fWaveLength[6] = 577.0; fPixelNo[6] = 775;
fWaveLength[7] = 579.1; fPixelNo[7] = 781;
fWaveLength[8] = 696.5; fPixelNo[8] = 1073;
fWaveLength[9] = 763.5; fPixelNo[9] = 1237;
fWaveLength[10] = 772.4; fPixelNo[10] = 1259;
fWaveLength[11] = 811.5; fPixelNo[11] = 1354;
fWaveLength[12] = 912.3; fPixelNo[12] = 1595;
fWaveLength[13] = 1014.0; fPixelNo[13] = 1835;
cviPolyFit(fPixelNo, fWaveLength, CalibrationNo,fCoefficient, 3);
HFILE file = _lcreat("SMSDK_test.txt",0);
char strTemp[80];
sprintf(strTemp," Pixel Wavelength(nm) Intensity \r\n");
_lwrite(file,(LPSTR)strTemp,strlen(strTemp));
for(int i=32;i<2080;i++)
{
double fWL;
cviPolyCalc(fCoefficient,3,i-31 ,&fWL);
sprintf(strTemp," %5d %5.2f %5d\r\n",i-31,fWL,(int)PixArray[i]);
_lwrite(file,(LPSTR)strTemp,strlen(strTemp));
}
_lclose(file);
dc.TextOut(0,m_nSite + 70,"Data is saved in SMSDK_test.txt ... OK!");
delete[] PixArray;
cviCloseEx(); //Close the board
dc.TextOut(0,m_nSite + 84,"All process for Data acquisition has been completed successfully... OK!");
}
C'est surout la partie en gras qui m'interresse !
Je ne sais pas du tout à quoi correspond la syntaxe "::" et comment interpreter les "Class" !?
Si quelqu'un pouvait m'aider, ou du moins m'expliquer, je lui en serait trés reconnaissant :))
Merci d'avance et bonne journée.
4 réponses
ben je te conseil de te documenter sur la POO car il n'y a pas d'equivalent pour les class et le "::".
On pourrais transformer les class en structure et les methode en fonctions mais pour l'heritage!? cela doit etre possible maisbon...
Mais pourquoi veux tu faire un lien entre les deux!?
Programmation objet et procedural etant diffrente?
la culture c comme la confiture - on en a + on l'etale
On pourrais transformer les class en structure et les methode en fonctions mais pour l'heritage!? cela doit etre possible maisbon...
Mais pourquoi veux tu faire un lien entre les deux!?
Programmation objet et procedural etant diffrente?
la culture c comme la confiture - on en a + on l'etale
Oui j'ai deja entendu parle de cela. Mais je me demandais dans quel but etais pose la question?
la culture c comme la confiture - on en a + on l'etale
la culture c comme la confiture - on en a + on l'etale
Salut,
merci pour vos pertinantes réponses,
même si je comprend pas tout, je me dis que l'on peut quand même faire quelquechose ! ;))
En effet, ce n'est peut-être pas du C++, mais il a été compilé avec Visual C++, c'est tout ce que je sais, il fait aussi appel à une librairie dynamique, une dll, puis il y a aussi un lien, je pense, c'est un fichier lib.
Mais bon voila, le compilateur que j'utilise n'accepte pas le C++, c'est pourquoi je voulais "essayer" modifier ce fichier afin de pouvoir m'en servir!
merci encore!
merci pour vos pertinantes réponses,
même si je comprend pas tout, je me dis que l'on peut quand même faire quelquechose ! ;))
En effet, ce n'est peut-être pas du C++, mais il a été compilé avec Visual C++, c'est tout ce que je sais, il fait aussi appel à une librairie dynamique, une dll, puis il y a aussi un lien, je pense, c'est un fichier lib.
Mais bon voila, le compilateur que j'utilise n'accepte pas le C++, c'est pourquoi je voulais "essayer" modifier ce fichier afin de pouvoir m'en servir!
merci encore!
Visual C++ n'accepte pas le C++ ?
Non ca c'est pas possible, il prend forcement par défaut le C++.
Tu peux aussi utiliser des compilos libres comme g++ pour le compiler mais si ton projet est fait avec Visual ca risque d'être trop compliqué.
Sinon, je vois parlé de win++ qu'est que c'est que ce langage ? J'en n'ai jamais entendu parlé.
Je veux bien quelques explications voire liens pour me faire une idée, en effet google ne resort que 6 pages qui traitent de win++ en francais.
Non ca c'est pas possible, il prend forcement par défaut le C++.
Tu peux aussi utiliser des compilos libres comme g++ pour le compiler mais si ton projet est fait avec Visual ca risque d'être trop compliqué.
Sinon, je vois parlé de win++ qu'est que c'est que ce langage ? J'en n'ai jamais entendu parlé.
Je veux bien quelques explications voire liens pour me faire une idée, en effet google ne resort que 6 pages qui traitent de win++ en francais.
pas d equivalent d un point de vue strict, c est vrai, mais tu peux garder la structure de ton programme avec des pointeurs de fonction.
l heritage, je dirai qu il faut inclure la structure "mere" dans la structure fille.
sinon j ai lu recemment qu on pouvait encapsuler un appel de fonction C++ dans une fontion C, avec
extern "C" ....
pour ceux que ca interesse:
http://www.google.fr/search?hl=fr&ie=UTF-8&oe=UTF-8&q=extern+%22C%22&btnG=Recherche+Google&meta=lr%3Dlang_fr
a part ca le code d au dessus c est pas du C++, c est du win++ a la rigueur.