|
Yes but isn't using ADO in C++ very complex? My program isn't COM-based so it may be a little difficult to implement. Are there other alternatives to using ADO?
|
|
|
|
|
I'm using ADO in my app and to be honest I don't even know what COM is. I didn't find it very difficult, I'm not aware of easier alternatives (but I'm no expert). This article was very helpful to me:
http://www.codeproject.com/database/simpleado.asp[^]
If you have any more questions I'd be glad to help but we should probably move this over to the SQL/ADO/ADO.NET message board.
|
|
|
|
|
Thanks Wilsonian! I'll try it out and if I'm still having problems I'll post it in the SQL/ADO/ADO.NET board. Thanks again!
|
|
|
|
|
Hello,
I'm using the following code to create database programatically, and it works only on WinXP, it crashesh on win98/ME/2000:
CDaoDatabase db;<br />
db.Create(_T("tmp.udb"));<br />
CDaoTableDef TableDef(&db);<br />
TableDef.Create(_T("Addresses"));<br />
TableDef.CreateField(_T("AddressID"), dbLong, 4, dbAutoIncrField);<br />
TableDef.Append();<br />
db.Close();
with error from daocore.cpp -> line:453
What am I doing wrong?
|
|
|
|
|
Im looking for a method of get the effective size of a dinamic array created with the new statement, because the sizeof instruction only gives me the size of the pointer or the size of the first element of the array, maybe that i don't know how use that, but i really want to know the size of an array without having the number of elements of the array, (if it's posibble) the same as UBound property in VB6.
PS: excuse if this text is a little confuse, i'm from argentina and my english is basic.
Thanks
|
|
|
|
|
Either the class that you use to create your dynamic array has member functions to check the size, or it doesn't. What class are you using to create your dynamic array?
|
|
|
|
|
What i want to do is something as:
char c[255];
int size;
int * myArray=new c;
size=Ubound(myArray); // this is the function what i like
// I do it any times and i want to know it size
// I need to know the lenght of the array, then i know if i can add another
// to the array.
|
|
|
|
|
The C++ inside me says:
Better to use some class for holding the array (what about ready-to-use stl::vector ?) that could return you the size of the array by using something line myArray.size() ? You will also get the automated memory management included and many more other stl usefull functions.
The C devil says:
on most compilers, the size of the array is stored at some negative offset of the array (but differs on compilers, also can differ on compiler versions etc - simply don't try it at home, it's ugly ugly ugly hack - just mentioned in case of emergency)
|
|
|
|
|
What you are after is not possible. You could pull it off while in debug mode, but the same trick would not work in release mode.
When you dynamically allocate memory, the amount requested is usually stored in a variable or a #define directive.
char *buff = new char[255]; Now whenever buff is used by other functions, the value 255 must also be sent to those functions. Make sense?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi Guys
I have to convert a IP-Address which is a CString to an UInt, but i have no clue how to do this. Also i must convert a Port CString to an UInt.
MFG
RedDragon2kx
Unix and C are the ultimate computer viruses.
|
|
|
|
|
don't you use a class that use ip addresses, and in which some function take a string (either char* or std::string or CString...) ?
else, you might write your own function that test first the validity of the address, and then, extract it to a UInt...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
You can sscanf the string like so:
CString sIPAddr;
UINT nByte1, nByte2, nByte3, nByte4;
UINT nPort;
DWORD dwIPAddr;
int nArgs = sscanf( (LPCTSTR)sIPAddr, "%d.%d.%d.%d:%d",
&nByte1, &nByte2, &nByte3, &nByte4, &nPort );
if( nArgs != 5 )
{
}
else
{
...
...
dwIPAddr = (nByte1 << 24) + (nByte2 << 16) + (nByte3 << 8) + nByte4;
}
You may want to verify my byte ordering (nByte4 may be the high byte) when building the dwIPAddr, but this should do the trick.
Bob Ciora
|
|
|
|
|
Thx. That fixed my problem.
Unix and C are the ultimate computer viruses.
|
|
|
|
|
For future reference, take a look at the inet_addr function in the MSDN library. I can't believe there isn't built in global c runtime functions for parsing an IP address in this day and age. But if you are programming with MFC or windows, you can use this windows function.
I hate the sscanf method myself. It seems wonderful on paper but there seem to be all kinds of weird issues when I try to use it. It never worked well for me as a validation tool for any kind of number. I always use the cruntime methods such as strtod for taking strings and validating them as actual numbers and converting them into an int value (for instance). Unfortunately, I don't see a c-run time method for IP addresses that would be more portable. Since I am a windows programmer, I have to settle for the windows libraries to provide this capability.
Shawn
|
|
|
|
|
Question. I have been doing c++ code for sometime now but only in console code. I am starting now to use MFC and I wanted to convert my old Console code into GUI MFC code. My Code relies heavily on Stream I/O with strings and character arrays, but I am having a problem getting my character arrays to output to my GUI correctly. I keep getting assertion errors when when running the program (NOTE: the program compiles error free).
Here is an example of what works:
void CParserDlg::OnParse()
{
char key[16]; //Make Array "Key"
strcpy(key, "Text Here"); //Copy "Text Here" into array
UpdateData(TRUE); //
m_strkey.Format(key); //Send String to Dialog Box
UpdateData(FALSE); //
}
This works fine and outputs the string "Text Here" to the dialog box. Now if I try and output 1 character and not the whole thing I get an assertion error:
void CParserDlg::OnParse()
{
char key[16]; //Make Array "Key"
strcpy(key, "Text Here"); //Copy "Text Here" into array
UpdateData(TRUE); //
m_strkey.Format(key[2]); //<------- Send String to Dialog Box
UpdateData(FALSE); //
}
Notice key[2] instead of just key. Not sure why it will not let me just output 1 character.
Thanks
|
|
|
|
|
I am going to go out on a limb here. Someone please correct me if I am wrong.
The first example works because a CString can be assigned the value of a character array:
m_strkey = key;
BUT a CString does not know what to do with a single character from an array. If you want to use the second example try:
m_strkey.Format("%s", key[2]);
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
Actually, the assignment operator works for both strings and characters, as per the MSDN documentation.
So you can simply do a:
m_strKey = key;
...
...
m_strKey = key[2];
As mentioned in the other reply, CString::Format is CString's version of sprintf(). You can use it to assign a string (as you did), since it didn't have any formatting characters in it. But CString is flexible enough that you can simply assign directly via =.
Bob Ciora
|
|
|
|
|
you are using CString::Format() the wrong way.
if you know about printf(), use Format() exactly the same...
so, if you want to print a single character, use Format("%c", key[2]);...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Thank you gentlemen. I never familiarized myself with printf() as I always used cout and cin for my Stream I/O before.
Again thank you.
|
|
|
|
|
Ok thanks guys for that, Now onto trying to outputting multiple characters. I have tried a couple of different ways, but to no avail thus far:
void CParserDlg::OnParse()
{
char key[16]; //Make Array "Key"
strcpy(key, "Text Here"); //Copy "Text Here" into array
UpdateData(TRUE); //
m_strkey.Format("%c", key[0]); //Output "T"
m_strkey.Format("%c", key[1]); //Output "e"
UpdateData(FALSE); //
}
void CParserDlg::OnParse()
{
char key[16]; //Make Array "Key"
strcpy(key, "Text Here"); //Copy "Text Here" into array
UpdateData(TRUE); //
m_strkey.Format("%c", key[0], key[1]); //Output "T" and "e"
UpdateData(FALSE); //
}
I also played with the UpdateData(), but again it will only output the last character I send which in this case is "e". "T" gets lost somewhere along the lines even if I send it by sending FALSE to UpdateData().
|
|
|
|
|
In both cases you are overwriting the 'T' character.
In the first case you are first setting the m_strkey to 'T' then
immediately changing it to 'e'
If you want to add the 'e' instead of changing from 'T' to 'e' use:
m_strkey.Format("%c", key[0]); //Output "T"
m_strkey += key[1];
Or you could just simply use
m_strkey = key[0];
m_strkey += key[1];
In the second case you are using a format string that only accepts one
character then passing two characters as arguments (of course only one is used):
m_strkey.Format("%c", key[0], key[1]); //Output "T" and "e"
Use:
m_strkey.Format("%c%c", key[0], key[1]); //Output "T" and "e"
Steve T
|
|
|
|
|
thank you.
I am learning this little by little. Its the little things that give me the most trouble. Do you know of any tutorials or articles where I can learn about this?
Thanks
|
|
|
|
|
I would lose the calls to UpdateData() . Rare is the case that it is ever useful.
You did not indicate what control on the dialog box is displaying the text so I will assume it is an edit control. In the dialog's class, you need a CEdit variable (e.g., m_edit ). Now your code can look like:
void CParserDlg::OnParse()
{
char key[16];
strcpy(key, "Text Here");
m_strkey = key;
m_edit.SetWindowText(m_strkey);
} or
void CParserDlg::OnParse()
{
m_strkey = "Text Here";
m_edit.SetWindowText(m_strkey);
} or
void CParserDlg::OnParse()
{
m_edit.SetWindowText("Text Here");
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thank you for the reply. I already have a CEdit variable in this case being: "m_strkey for the Edit Box which I am outputting to (you we're correct on that assumption).
I tried using SetWindowText() instead of Format(), but I keep getting an error:
error C2039: 'SetWindowTextA' : is not a member of 'ATL::CStringT<basetype,stringtraits>'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]
Not sure why it says "SetWindowTextA", I only have "SetWindowText".
|
|
|
|
|
Is there a way, in a Visual Studio .NET Setup project, that you can make a custom folder under the Application folder that will include all the files from some source directory? I only see a way of specifiying individual files to add to the folders. I just want this folder to include c:\somefolder\*.* and not worry about adding and removing individual files if it changes.
Thank you
|
|
|
|