|
Hey no problem at all. It's fun to help out people. You can define the enum globally, although it is cleaner and more "object oriented" to only put the enums in the classes that actually need and use them. That said, if you want to use those same enum values all over the place in other unrelated classes, that's when you'd want to think about defining it in the global scope and putting it in some header. So long as your enum variables aren't global, a global enum typedef won't displease the OO fanatics out there
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
I did:
case Mode1:
int index = 0;
KeyValueMap & keyValueMap = *m_kVMap;
KeyValueMap::iterator it = keyValueMap.begin();
for(; it != keyValueMap.end(); it++)
{
m_listAddRecord.InsertItem(index, (*it).first);
index++;
}
CString temp = m_listAddRecord.GetItemText(0,0);
m_editAddedKW.SetWindowText(temp);
m_editAddedVal.SetWindowText("");
m_editAddedVal.SetFocus();
m_DoneAdd.EnableWindow(TRUE);
case Mode2:
The compiler errors said I was skipping initialization of "temp" and "it" with the case statement. Do I need a return or something somewhere?
I'm doing it with if m_Mode == Mode1 but yours was so cool...
Any idea what its not happy about and how to fix it?
Thanks,
ns
|
|
|
|
|
Yeah... with a case statement it is possible to jump over code that would otherwise be executed. It's almost like a goto statement. For instance, when case is Mode1, you're going to execute all of the code up to where Mode2 starts. What happens if you don't put a break in there, like you've got in your sample? Well in C++, unlike VB, you keep executing right through to the next case statement. This is one of those classic "gotcha" bugs. This by itself is not an error, however, because it is perfectly legal to want to keep executing the code in the next case section.
Someone doing this "case fall through" scenario on purpose might be thinking they can keep using the variables they declared in the previous case block for Mode1. Which might be true if you always executed the code for case Mode1. But you're not guaranteed that, since you might come in directly at case Mode2. Mode2 skips all of those variable declarations and initializations. Your variables don't exist there, so they can't be used nor referenced in that scope. This is a paradox between otherwise legal code and its run-time handling. As such, you have to give another layer of scope to declare any variables inside a case section. Here's some sample code:
std::vector< int > OuterVector;
switch( i )
{
std::vector< int > SwitchVector;
case 1:
{
std::vector< int > InnerVector;
std::vector< int >::iterator itInnerVector;
}
case 2:
{
}
break;
}
As you can see, I've added some block braces {} around the code for both case 1 and 2. This defines a new scope for those variables declared inside the block. They can only be used within that scope since they will be destroyed as soon as execution leaves that scope. If you tried to reference those variables in case 2, you'd get a compiler error because they don't exist.
If indeed you wanted to use the same variables in both case Mode1 and Mode2 when you fell through on purpose, you'd have to declare those variables either before the switch statement, as I've done above with OuterVector, or immediately after the switch but before any case statements are specified, as you see with SwitchVector. The former is a little clearer for other people to understand, but there might be scope issues that require the switch-level scope of the latter.
So, the long story short: wrap your case sections with curly braces. This should help to understand why it is considered an error, however. I've become so accustomed to adding braces to case blocks that I don't even think twice about it when they come out of my fingertips automatically. Here's your sample code tweaked a little bit:
case Mode1:
{
int index = 0;
KeyValueMap & keyValueMap = *m_kVMap;
KeyValueMap::iterator it = keyValueMap.begin();
for(; it != keyValueMap.end(); it++)
{
m_listAddRecord.InsertItem(index, (*it).first);
index++;
}
CString temp = m_listAddRecord.GetItemText(0,0);
m_editAddedKW.SetWindowText(temp);
m_editAddedVal.SetWindowText("");
m_editAddedVal.SetFocus();
m_DoneAdd.EnableWindow(TRUE);
}
break;
case Mode2:
I'm guessing from your previous posts that you don't really want to fall through from case Mode1 to Mode2. So remember to add that break statement before the case Mode2 code starts. That's one key difference between the VB syntax and VC
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
What a truly excellent explanation. Thank you so much. Indeed I need the 'break'. Have a good weekend!
Thanks,
ns
|
|
|
|
|
You bet, have a good weekend too!
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
This is perfectly valid and most usual, particularly if differences are not wild (i.e. if you're not forced to check for m_flag in every handler).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
hello,
i'd like to get the parent IShellFolder, but i don't want to use the SHBindToParent function because i want my program to work on windows 98.
how can i do that ?
|
|
|
|
|
Vassili Bourdo's ITEMIDLIST management library
[^] provides a replacement of the function for Windows 9x/NT.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
thanks very much my friend
|
|
|
|
|
I used the defines :
<br />
#typedef unsigned hyper ulonglong;<br />
<br />
#define uint8korr(A) (*((ulonglong *) (A)))<br />
#define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A)<br />
In my code, pbuf is a PBYTE pointed to
1 e1 f5 5 0 0 0 0
When I want to store the data into another buffer pdata, I did:
int8store(pdata, pbuf);
I got the dump of pdata becomes:
e0 2e 35 1 0 0 0 0
Anything wrong ??? It seems it's just doing casting and then setting A = B stuff. Why did the value has changed ?
|
|
|
|
|
#define int8store(T,A) *((ulonglong*)(T))=(ulonglong)(*(A)) (I think)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Need help from guru!
I need to pass a CList to another function.
When I just pass to CList* plist = &pTeacher;
it doesn't work! please help!
my Clist is like this,
CList<cteacher, cteacher=""> pTeacher;
// CTEACHER is a structure.
Thank for attention!
JW
|
|
|
|
|
This cannot possibly compile, as CList is missing the type of objects it should contain. Try declaring it like CList<CTEACHER> .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I will try, thanks!
JW
|
|
|
|
|
hi i'm having some problems in inserting a UNICODE string into a database.
always saves "??????". I'm trying to write some HINDI chars..
can someone help me??
thnx
|
|
|
|
|
Both the database and the GUI on top of it must support Unicode, and it sounds like the GUI does not. (When characters show up as ?, it means the app (or OS, during the paste) tried to convert the Unicode to ANSI, but the ANSI code page in use did not contain the character.)
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
well that's why i'm sending the code:
here it is an example:
m_rs.m_teste = _T("Hello India \x0939\x093f\x0928\x094d\x0926\x093f");
if i do the same into a Unicode file it works..
|
|
|
|
|
Can someone please tell me how to use delay loading of DLLs? Specifically,
1. Do I need to do anything while building the DLL that I want to "delay-load"?
2. What do I need to do to my project settings so that it can delay load a particular dll?
3. Most importantly, do I need to change any of my existing code which calls the functions in the dll (the existing code was written to call the functions from a static lib)?
4. The reason I want to delay load is that I want to provide the user with an option to upgrade the software, hence the choice of DLLs and I don't want to insert numerous calls to LoadLibrary() and GetProcAddress() all over my code, hence delay loading. That will take just too long and I don't want to litter my code anyway, if there is an alternative. Did I get it right? Will delay loading let my existing (caller) code remain as it is, with maybe only a few changes to write a helper function and the likes? How do I use the helper function anyway? Do I need to call each function in the DLL through this function? In that case it is as bad as LoadLibrary() and GetProcAddress() . Is there any other way?
Thanks very much in advance.
PS: Yes, I tried to RTFM, but after going through the MSDN docs, I was as confused as before. Can someone explain all this to me in plain English?
Regards,
Rohit Sinha
|
|
|
|
|
Rohit Sinha wrote:
1. Do I need to do anything while building the DLL that I want to "delay-load"?
No.
Rohit Sinha wrote:
2. What do I need to do to my project settings so that it can delay load a particular dll?
In your linker settings, add delayimp.lib to the list of libs, then in the parameters section (bottom of the tab) add /delayload:dllname.dll (for example, /delayload:uxtheme.dll )
Rohit Sinha wrote:
3. Most importantly, do I need to change any of my existing code which calls the functions in the dll
No.
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Hi,
I would like to read the return value from a stored procedure in ADO but nothing.
I can write datas to a database by my stored procedure but I cannot read the output value.
The stored procedure is OK.
If anyone can help me with a little code or a website or some informations it is great.
Best Regards
youssef
|
|
|
|
|
Assuming your stored proc looks something like this:
create procedure my_proc( @param1 int )
as
begin
return 1
end
here's how you'd code it up with ADO:
#define ADO_TESTHR(x) { if FAILED(x) _com_issue_error(x); };
_ConnectionPtr pConn;
_CommandPtr pCmd;
_variant_t vtValue;
try
{
ADO_TESTHR( pConn.CreateInstance( "ADODB.Connection" ) );
ADO_TESTHR( pCmd.CreateInstance( "ADODB.Command" ) );
.. open your connection pConn->Open something
pCmd->ActiveConnection = pConn;
pCmd->CommandText = "dbo.my_cool_proc";
pCmd->CommandType = adCmdStoredProc;
pCmd->Parameters->Append( pCmd->CreateParameter( "param1", adInteger, adParamInput, sizeof(int) ) );
pCmd->Parameters->Append( pCmd->CreateParameter( "return", adInteger, adParamReturnValue, sizeof(int) ) );
pCmd->Parameters->Item["param1"]->Value = 1234;
pCmd->Execute( NULL, NULL, adCmdStoredProc );
vtValue = pCmd->Parameters->Item["return"]->Value;
if( vtValue.vt == VT_I4 )
{
TRACE( "%lu\n", static_cast< long >( vtValue ) );
}
}
catch( _com_error &ce )
{
}
try
{
if( pConn )
{
if( pConn->State != adStateClosed )
{
pConn-Close();
}
}
}
catch( ... )
{
}
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
Thank yo for the answer.
Please find here my sample code with the stored procedure.
With my code I can't retrieve the output value.
Best Regards
void CStoreProcedureDlg::OnWriteData()
{
//Initialize the connection with the Database RTLSQL1 ARCHIVES_NUM
//COM initialization
CoInitialize (NULL);
_ConnectionPtr m_pConn2("ADODB.Connection");
_ParameterPtr pParam2,pParam3;
try
{
//Check if I can create a instance for a connection into a db
HRESULT hr = m_pConn2.CreateInstance (__uuidof (Connection));
if (FAILED (hr))
{
// Automat_LOG_WITH_TIME(_T("DB : Can't create intance of Connection"));
}
else
{
// Automat_LOG_WITH_TIME(_T("DB : I can create intance of Connection"));
}
CString strFileName = "JA980630";
//Check if I can Open a session in the ARCHIVES_TVI
if (FAILED (m_pConn2->Open("provider=sqloledb.1;database=ARCHIVES_TVI;server=1.1.1.1;uid=xxx;pwd=xxx;network=dbmssocn","","",adConnectUnspecified)))
{
// Automat_LOG_WITH_TIME(_T("DB : Can't open datasource ARCHIVES_TVI"));
// Automat_Send_SMS(_T("DB : Can't open datasource ARCHIVES_TVI"),_T(""));
}
else
{
//Automat_LOG_WITH_TIME(_T("DB : I can open datasource ARCHIVES_TVI"));
CString sT;
sT.Format("%d",1);
_variant_t varLiReturn;
int liReturn = -99;
_CommandPtr pCmd2("ADODB.Command");
pCmd2->ActiveConnection = m_pConn2;
//Store procedure for the DATABASE ARCHIVES_NUM
pCmd2->CommandText = "StartFileNumV3";
pParam2 = pCmd2->CreateParameter ( _bstr_t ("FileName"), adVarChar,
adParamInput, strFileName.GetLength (), (_bstr_t) strFileName);
pCmd2->Parameters->Append ( pParam2);
pParam2 = pCmd2->CreateParameter ( _bstr_t ("AutomatNr"), adInteger,
adParamInput, sizeof(int), _variant_t (sT));
pCmd2->Parameters->Append ( pParam2);
// pCmd2->Parameters->Item[_variant_t((long)1)]->Direction = adParamReturnValue;
pParam2 = pCmd2->CreateParameter(_T("Status"),adInteger,adParamOutput,sizeof(int),varLiReturn);
pCmd2->Parameters->Append ( pParam2);
//pParam2->Value = vtroyal;
_RecordsetPtr pRecordset;
pRecordset.CreateInstance(__uuidof(Recordset));
pRecordset = pCmd2->Execute(NULL, NULL, adCmdStoredProc);
varLiReturn = pCmd2->Parameters->Item[_T("Status")]->Value;
Sleep(100); //ms
//Automat_LOG_WITH_TIME(_T("DB : The Store Procedure have been execute with success (StartFileNum)"));
//Close the DATABASE
if ( (m_pConn2->State & adStateOpen) == adStateOpen)
{
m_pConn2->Close();
// Automat_LOG_WITH_TIME(_T("DB : I can close datasource RTLSQL1 ARCHIVES_TVI"));
}
else
{
// Automat_LOG_WITH_TIME(_T("DB : I can't close datasource RTLSQL1 ARCHIVES_TVI"));
}
}
}
catch ( _com_error &e )
{
_bstr_t bstrSource (e.Source());
_bstr_t bstrDescription (e.Description());
CString sErrorDB;
sErrorDB.Format("DB : ERROR !!!!! ARCHIVES_TVI\r\nException thrown for classes generated by #import\r\nCode = %08lx\r\nCode meaning = %s\r\nSource = %s\r\nDescription = %s\r\n", e.Error (), e.ErrorMessage (), (LPCTSTR) bstrSource, (LPCTSTR) bstrDescription);
// Automat_LOG_WITH_TIME(sErrorDB);
MessageBox (sErrorDB, bstrDescription,MB_OK);
}
catch (...)
{
TRACE ( "*** Unhandled Exception ***" );
}
Sleep(100); //ms
CoUninitialize();
}
__________________________________________________________________________________
The stored procedure :
CREATE PROCEDURE StartFileNumV3
(
@FileName varchar(8), @AutomatNr int, @Status int OUTPUT
)
AS
declare @Now datetime
declare @Nbr int
set @Nbr = (SELECT COUNT(*) FROM Num_Files WHERE (File_Name = @FileName))
if @Nbr = 1
begin
set @Nbr = (SELECT COUNT(*) FROM Num_Files WHERE (File_Name = @FileName) and (SetNumReady is not null) and (DateSetNumReady is not null))
if @Nbr = 1
begin
set @Now = GetDate()
UPDATE Num_Files SET Num_Go = @Now, AutomatNr = @AutomatNr WHERE File_Name = @FileName
SET @Status = 1
end
else
begin
/*La référence du fichier est présente dans la table, mais celle-ci ne doit pas se trouver dans la BétaCart ...*/
SET @Status = 2
end
end
else
begin
/*La référence du fichier n'est pas présente dans la table ...*/
SET @Status = 0
end
SELECT @Status
GO
youssef
|
|
|
|
|
Ahh, your procedure has an output parameter, not a return value. That's a little different. What happens with this line of code:
varLiReturn = pCmd2->Parameters->Item[_T("Status")]->Value;
Does varLiReturn contain the right value, or do you get something incorrect? Does it throw a COM error at that point, or ? Everything looks okay just from a quick glance.
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
Is that I must to force a ReturnValue in my stored procedure for resolve my problem ?
Best Regards
youssef
|
|
|
|
|
No, you can definitely use output parameters in ADO. I do them all the time. What exactly is going wrong when you execute your code? It looks okay from looking at it, but it will help to know what is happening. Does it throw a _com_error, or is the value just wrong?
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|