Click here to Skip to main content
15,898,588 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Winsock question? Pin
Vladimir Georgiev1-Mar-02 6:29
Vladimir Georgiev1-Mar-02 6:29 
GeneralRe: Winsock question? Pin
Nish Nishant1-Mar-02 6:37
sitebuilderNish Nishant1-Mar-02 6:37 
GeneralRe: Winsock question? Pin
Jon Hulatt1-Mar-02 7:15
Jon Hulatt1-Mar-02 7:15 
GeneralRe: Winsock question? Pin
Vladimir Georgiev1-Mar-02 6:31
Vladimir Georgiev1-Mar-02 6:31 
GeneralRe: Winsock question? Pin
Vladimir Georgiev1-Mar-02 6:34
Vladimir Georgiev1-Mar-02 6:34 
GeneralRe: Winsock question? Pin
Nish Nishant1-Mar-02 6:43
sitebuilderNish Nishant1-Mar-02 6:43 
GeneralRe: Winsock question? Pin
lucy1-Mar-02 8:08
lucy1-Mar-02 8:08 
Questionhow could i keep the value of a specific pointer? Pin
Gérald Mercet1-Mar-02 3:13
Gérald Mercet1-Mar-02 3:13 
In my dialog app i have 2 functions which use ADO connection to catch value from a database, and which put them into a "C" pointer of pointer and a regular pointer. I want after in a third function use the 2 pointers, which represent some of the input data. As i do it with 3 different button which each of them call one and only one function.

For example the first, called OnLoadCorrel, put a whole matrix into a **pCorrel, the second one called On LoadVol, put a whole array into a *pVol. And, finally, the 3 function use the values needed coming from the matrix and the array. It's at this point of my app that there's a pb, because when i call the third function, the app doesn't recognize (or know) the value into both the pointers (perhaps the value have been lost?!?)

So you could see the following lost, and i hope that soeone could find if what is wron in my app.

/////////////////////////////////////////////////////////
So, in the CalcRiskPortDlg.cpp::

void CCalcRiskPortDlg::OnLoadVol()
{
UpdateData(TRUE);
::CoInitialize(NULL);
LoadTables Table(m_dlgSector);
int i;
// _variant_t IndexCol;
CString strValue;

try
{
_ConnectionPtr pConnection=NULL;
CString strTemp;
strTemp.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\CalcRiskPort\\vol_correl1.mdb;");
_bstr_t strCnn(strTemp);
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
pConnection->Open(strCnn,"","",adConnectUnspecified);

_RecordsetPtr pTp("ADODB.Recordset");
try
{

pTp->Open("Volatilité",strCnn,adOpenStatic,adLockOptimistic,adCmdTableDirect);

if(!pTp->EndOfFile)
{
for(i=1;i<=m_dlgSector;i++)
{
pTp->MoveFirst();
pTp->Move(i-1);
//strIndexCol=Table.ConvIntToVar((double)j);
//strIndexCol=strIndexCol+strT;
//_variant_t IndexCol(strIndexCol);
*(Table.pVol+i)=pTp->Fields->GetItem("Volatilité")->Value;
}
}

//dValue=pTp->Fields->GetItem("N° Titre")->Value;
//Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;

pTp->Close();
}
catch(_com_error &e)
{
AfxMessageBox("a pas bon");
}
m_dlgValue=Table.pVol[3];
strValue.Format("%.9f",m_dlgValue);
CEdit* PEdit=(CEdit*)GetDlgItem(IDC_VALUE);
PEdit->SetWindowText(strValue);
//Table.free_dmatrix(Table.pCorrel,1,m_dlgPortWeight,1,m_dlgPortWeight);
pConnection->Close();


}
catch(_com_error &e)
{
AfxMessageBox("a pas bon");
}


::CoUninitialize();

// TODO: Add your control notification handler code here

}

void CCalcRiskPortDlg::OnLoadCorrel()
{
UpdateData(TRUE);
::CoInitialize(NULL);
LoadTables Table(1,m_dlgSector,1,m_dlgSector);
int i,j;
// _variant_t IndexCol;
CString strValue,strT,strIndexCol;
strT="t";

//Table.pCorrel=Table.dmatrix(1,m_dlgPortWeight,1,m_dlgPortWeight);
try
{
_ConnectionPtr pConnection=NULL;
CString strTemp;
strTemp.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\CalcRiskPort\\vol_correl1.mdb;");
_bstr_t strCnn(strTemp);
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
pConnection->Open(strCnn,"","",adConnectUnspecified);

_RecordsetPtr pTp("ADODB.Recordset");
try
{

pTp->Open("Correlation",strCnn,adOpenStatic,adLockOptimistic,adCmdTableDirect);

if(!pTp->EndOfFile)
{
for(i=1;i<=m_dlgSector;i++)
{
for(j=1;j<=m_dlgSector;j++)
{
pTp->MoveFirst();
pTp->Move(i-1);
strIndexCol=Table.ConvIntToVar((double)j);
strIndexCol=strIndexCol+strT;
_variant_t IndexCol(strIndexCol);
*(*(Table.pCorrel+i)+j)=pTp->Fields->GetItem(IndexCol)->Value;
}
}
}

//dValue=pTp->Fields->GetItem("N° Titre")->Value;
//Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;

pTp->Close();
}
catch(_com_error &e)
{
AfxMessageBox("a pas bon");
}
m_dlgValue=Table.pCorrel[3][7];
strValue.Format("%.9f",m_dlgValue);
CEdit* PEdit=(CEdit*)GetDlgItem(IDC_VALUE);
PEdit->SetWindowText(strValue);
//Table.free_dmatrix(Table.pCorrel,1,m_dlgPortWeight,1,m_dlgPortWeight);
pConnection->Close();


}
catch(_com_error &e)
{
AfxMessageBox("a pas bon");
}


::CoUninitialize();
// TODO: Add your control notification handler code here

}

void CCalcRiskPortDlg::OnCalcvar()
{
UpdateData(TRUE);
::CoInitialize(NULL);

LoadTables Table;
double Var;
double *pTabVar=new double[pow(2,m_dlgSector)];
CString strValue;

int *pTabBinPort=new int[m_dlgAsset];
int *pTabNumPort=new int[m_dlgAsset];

int k,i;
i=0;

for(k=0;k<=m_dlgAsset-1;k++)
{
*(pTabBinPort+k)=0;

Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort);
}
*pTabVar=Table.CalcVar(pTabNumPort,m_dlgAsset);

for(i=1;i<=pow(2,m_dlgSector);i++)
{
k=m_dlgSector-1;

while(*(pTabBinPort+k)==1)
{
*(pTabBinPort+k)=0;
Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort);
k--;
}
*(pTabBinPort+k)=1;
Table.ConvertBinToNum(k,pTabBinPort,pTabNumPort);

*(pTabVar+i)=Table.CalcVar(pTabNumPort,m_dlgAsset);
}
m_dlgValue=pTabVar[2];
strValue.Format("%.9f",m_dlgValue);
CEdit* PEdit=(CEdit*)GetDlgItem(IDC_VALUE);
PEdit->SetWindowText(strValue);
delete []pTabVar;
delete []pTabNumPort;
delete []pTabBinPort;
::CoUninitialize();

// TODO: Add your control notification handler code here

}
///////////////////////////////////////////////////////////
and for information the LoadTable.cpp code where you could find others function's definitions:

#include "stdafx.h"
#include "CalcRiskPort.h"
#include "LoadTables.h"

#define NR_END 1
#define FREE_ARG char*
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
LoadTables::LoadTables()
{

}

LoadTables::LoadTables(long a,long b,long c,long d)
{
//free_dmatrix(pCorrel,a,b,c,d);

pCorrel=dmatrix(a,b,c,d);

}

LoadTables::LoadTables(long a)
{
pVol=NULL;
Delete_pVol();
pVol=new double [a];
}

void LoadTables::Delete_pVol()
{
if(pVol!=NULL)
{
delete[] pVol;
pVol=NULL;
}
}

LoadTables::~LoadTables()
{

}

void LoadTables::nrerror(char error_text[])
{
AfxMessageBox("Ca marche moyen");
exit(1);
}

double **LoadTables::dmatrix(long LowRow,long HighRow,long LowCol,long HighCol)
{
long i, RowSize=HighRow-LowRow+1,ColSize=HighCol-LowCol+1;

double **m;

m=(double **)malloc((size_t)((RowSize+NR_END)*sizeof(double*)));
if(!m)nrerror("pb allocation1 in matrix()");

m +=NR_END;
m -=LowRow;

m[LowRow]=(double *)malloc((size_t)((RowSize*ColSize+NR_END)*sizeof(double)));
if(!m[LowRow])nrerror("pb allocation2 in matrix()");

m[LowRow] +=NR_END;
m[LowRow] -=LowCol;

for(i=LowRow+1;i<=HighRow;i++)
m[i]=m[i-1]+ColSize;

return m;
}


void LoadTables::free_dmatrix(double **m,long LowRow,long HighRow,long LowCol,long HighCol)
{

free((FREE_ARG)(m[LowRow]+LowCol-NR_END));
free((FREE_ARG)(m+LowRow-NR_END));

}

CString LoadTables::ConvIntToVar(double j)
{
CString strIndexCol;
int decimal,sign;

strIndexCol=_fcvt(j,0,&decimal,&sign);

//_variant_t IndexCol(strIndexCol);

return strIndexCol;

}

double LoadTables::ReturnValue(long Row,_variant_t IndexCol, _variant_t ParamTable)
{

double dValue;
CString strTemp;
strTemp.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\CalcRiskPort\\vol_correl1.mdb;");
_bstr_t strcnn(strTemp);
_RecordsetPtr pTp("ADODB.Recordset");

try
{
pTp->Open(ParamTable,strcnn,adOpenStatic,adLockOptimistic,adCmdTableDirect);
pTp->MoveFirst();
pTp->Move(Row-1);
if(!pTp->EndOfFile)
dValue=pTp->Fields->GetItem(IndexCol)->Value;
//dValue=pTp->Fields->GetItem("N° Titre")->Value;
//Parameter2=pTp->Fields->GetItem(IndexColumn)->Value;

pTp->Close();

}

catch(_com_error &e)
{

AfxMessageBox("Table non atteinte");
pTp->Close();

}

return dValue;

}

double LoadTables::CalcVar(int* pTabNumPort,int NbOfAsset)
{
int i,j;
double sum1,sum2,sum;

sum=sum1=sum2=0;

for(i=1,j=0;i<=NbOfAsset,j
GeneralNet Send Message Pin
1-Mar-02 0:21
suss1-Mar-02 0:21 
GeneralGuarding delete Pin
Joe Moldovan28-Feb-02 23:49
Joe Moldovan28-Feb-02 23:49 
GeneralRe: Guarding delete Pin
Joaquín M López Muñoz1-Mar-02 0:35
Joaquín M López Muñoz1-Mar-02 0:35 
GeneralRe: Guarding delete Pin
Jon Hulatt1-Mar-02 4:12
Jon Hulatt1-Mar-02 4:12 
GeneralRe: Guarding delete Pin
Le centriste1-Mar-02 5:02
Le centriste1-Mar-02 5:02 
GeneralRe: Guarding delete Pin
Joe Moldovan1-Mar-02 11:56
Joe Moldovan1-Mar-02 11:56 
GeneralRe: Guarding delete Pin
Mukkie1-Mar-02 12:06
Mukkie1-Mar-02 12:06 
GeneralTimers are as threads? (newbie) Pin
Joan M28-Feb-02 22:18
professionalJoan M28-Feb-02 22:18 
GeneralRe: Timers are as threads? (newbie) Pin
Joaquín M López Muñoz28-Feb-02 23:41
Joaquín M López Muñoz28-Feb-02 23:41 
GeneralRe: Timers are as threads? (newbie) Pin
Steen Krogsgaard1-Mar-02 3:34
Steen Krogsgaard1-Mar-02 3:34 
GeneralRe: Timers are as threads? (newbie) Pin
Joan M1-Mar-02 4:54
professionalJoan M1-Mar-02 4:54 
GeneralRe: Timers are as threads? (newbie) Pin
Bill Wilson1-Mar-02 6:09
Bill Wilson1-Mar-02 6:09 
GeneralRe: Timers are as threads? (newbie) Pin
Steen Krogsgaard3-Mar-02 21:30
Steen Krogsgaard3-Mar-02 21:30 
QuestionHow to access network shared resource from a service? Pin
28-Feb-02 21:21
suss28-Feb-02 21:21 
AnswerRe: How to access network shared resource from a service? Pin
Bill Wilson1-Mar-02 6:20
Bill Wilson1-Mar-02 6:20 
GeneralStandard Conversions about char Pin
28-Feb-02 19:38
suss28-Feb-02 19:38 
GeneralRe: Standard Conversions about char Pin
Joaquín M López Muñoz28-Feb-02 20:12
Joaquín M López Muñoz28-Feb-02 20:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.