|
Don't use MFC arrays at all - they are crap. Use std::vector. I have some tutorials on CP, and there are others, too.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
I want to create a array (CArray, CPtrArray, ...) of pointer to a class, like "CMeasureItems*". I have no experience with arrays in mfc, so could anyone tell me what kind of mfc array I should use?!?!
CTypedPtrArray<cptrarray, cmeasurementitem*=""> m_measureItems; ????
or
CArray<cmeasurementitem*, cmeasurementitem*=""> m_measureItems; ????
...
????
--
Nice greets, Daniel.
|
|
|
|
|
try std::vector<cmeasureitems *="">
|
|
|
|
|
Hi...
With MFC you've 3 types of simple container
1. Array : with CArray
2. List : with CList (very useful)
3. Map : with CMap
You've also containers of typed pointers. For example CTypedPtrList
With CArray, use this command for an array of CPoint named PointArray
CArray<CPoint, CPoint&> PointArray;
To add a point:
PointArray.Add(aPoint);
Advice: It's recommended to use the method SetSize() for initialize the size of the array and avoid a lot of reallocation.
To extract an element:
aPoint = PointArray.GetAt(2);
To change an element:
PointArray.SetAt(3, NewPoint); // stock the NewPoint in the place of the 4th element
But I find CList more useful...
With CList, use this comand for a list of CPoint named PointList
CList<CPoint, CPoint&> PointList;
To add a point:
PointList.AddTail(aPoint); // in the end of the list
PointList.AddHead(aPoint); // in the head of the list
To insert a point:
PointList.InsertBefore(aPosition, ThePoint); // before the aPosition (type = POSITION)
PointList.InsertAfter(aPosition, ThePoint); // afterthe aPosition (type = POSITION)
The GetNext() return a value of type POSITION which is the position of the next pointed element.
For an iteration inside the list use this loop:
CPoint CurrentPoint(0,0);<br />
POSITION aPosition = PointList.GetHeadPosition();<br />
while(aPosition)<br />
{<br />
CurrentPoint = PointList.GetNext(aPosition);<br />
}
For more information... MSDN of course (but it's really a mess)
Hello World!!!
from Raphaël
|
|
|
|
|
Raphaël Kindt wrote:
But I find CList more useful...
Leaving aside that MFC containers are garbage, are you aware of the COST of list compared to an array ? A list is quicker to insert or remove, especially in the middle. It is far slower though, when you're looking up items, because it needs to step from one to another until it finds the one it wants. For this reason, stl::list has it's own sort, instead of the faster sort provided for random access iterators, that is, containers where you can go direct to the item you have the index for instead of counting up to it.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
of course...
I did not want anything to impose by saying that.
All belong to the application... (for mine CList was useful. But what you say is true)
I am not an expert with STL but I learns. Many of my friends say only good things on the STL...
Hello World!!!
from Raphaël
|
|
|
|
|
If you want another solution (faster and managing the memory better) use STL (Standard Template Library)...
Hello World!!!
from Raphaël
|
|
|
|
|
I have ADO in my project with a #import msado25.tlb. I see that if I want to peek into my db and check the name of the table, I need to use ADOX. But when I do the #import msadox.dll I get redefinition problems.
So, is there a way to get the table name using only ADO. If not how do I get ADOX and ADO to reconcile. As soon as i put in the #import for ADOX I get errors of redefinition!
Thanks,
Need to know this desperately.
ns
|
|
|
|
|
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" rename_namespace("ADO") rename("EOF", "EndOfFile")<br />
#import "c:\Program Files\Common Files\system\ado\msadox.dll" no_namespace
If I remember correctly you need to specify a namespace for ADO.
Michael
Programming is great. First they pay you to introduce bugs into software. Then they pay you to remove them again.
|
|
|
|
|
All I did was replace my
#import "C:\\Program Files\\Common Files\\System\\ADO\\msado25.tlb" \
no_namespace \
rename( "EOF", "adoEOF" )
with your
rename_namespace "ADO" and I got 234 compile errors! I hadnt even breathed ADOX yet!!
Now what?
thanks,
ns
|
|
|
|
|
All the ADO objects are now in the ADO namespace and will need to be accessed via the namespace.
e.g
_ConnectionPtr becomes ADO::_ConnectionPtr
Michael
Programming is great. First they pay you to introduce bugs into software. Then they pay you to remove them again.
|
|
|
|
|
|
I want tio use a CP CADOX class which has stuff called ADODB::_CommandPtr etc. Will this cause a conflict with ADO::_CommandPtr etc?
thanks,
ns
|
|
|
|
|
does this (__uuidof(Recordset) ) become ADO::Recordset?
|
|
|
|
|
Okay. I have been able to compile doing what you said. Now the test will be if I can do ADOX stuff!!!
Thanks forhelping as much as you have. I'm sure I'll be back with ADOX questions in a bit!
Appreciate the hint!
Still, why does this work?
|
|
|
|
|
Is it okay if I have multiple #imports in various files? I need to use a CP ADOX class, and it has
a #import msadox.dll in it as well...
Or should these #imports be declared only once in the project?
Also is it okay that I'm using msado25.tlb not msado15.dll? On some machines my project only works if I have the former (they dont have the latest mdac) . No conflict with msadox.dll right?
|
|
|
|
|
nss wrote:
Also is it okay that I'm using msado25.tlb not msado15.dll? On some machines my project only works if I have the former (they dont have the latest mdac) . No conflict with msadox.dll right?
There shouldn't be any problem.
nss wrote:
Or should these #imports be declared only once in the project?
I just have the #imports declared in one place, in my header file for my ADOConnection wrapper class.
Michael
Programming is great. First they pay you to introduce bugs into software. Then they pay you to remove them again.
|
|
|
|
|
Try this:
#pragma warning(disable: 4146)
#import "msado15.dll" rename("EOF", "adoEOF")
#import "msadox.dll" rename("DataTypeEnum", "AdoxDataTypeEnum")
#pragma warning(default: 4146)
All of the ADO stuff will be in the ADODB namespace.
All of the ADOX stuff will be in the ADOX namespace.
|
|
|
|
|
I have a databadse project with
#import msado25.tlb
Now i want some ADOX functionlaity so I added:
#import "c:\Program Files\Common Files\system\ado\msadox.dll" no_namespace
I get 18 redefinition errors! How can I get around this and use ADOX and ADO in the same project?
Thanks,
ns
|
|
|
|
|
Hello ns. I don't know much about ADO(X), but this might help:- Can't you just use ADOX and forget about ADO? As it name suggests, probably ADOX covers ADO as well.
- If you can't, you might try using ADO and ADOX in different
.cpp s so that no name clash occurs.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I added #include "adox.h" to my db project and got these errors:
--------------------Configuration: Train1 - Win32 Release--------------------
Compiling...
Train1View.cpp
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tlh(104) : error C2011: '_Collection' : 'struct' type redefinition
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tlh(133) : error C2011: '_DynaCollection' : 'struct' type redefinition
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tlh(511) : error C2011: 'DataTypeEnum' : 'enum' type redefinition
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tlh(554) : error C2011: 'Properties' : 'struct' type redefinition
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tlh(580) : error C2011: 'Property' : 'struct' type redefinition
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(14) : error C2084: function 'long __thiscall _Collection::GetCount(void)' already has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(21) : error C2084: function 'class _com_ptr_t<class _com_IIID<struct IUnknown,&struct __s_GUID _GUID_00000000_0000_0000_c000_000000000046> > __thiscall _Collection::_NewEnum(void)' a
lready has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(28) : error C2084: function 'long __thiscall _Collection::Refresh(void)' already has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(38) : error C2084: function 'long __thiscall _DynaCollection::Append(struct IDispatch *)' already has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(44) : error C2084: function 'long __thiscall _DynaCollection::Delete(const class _variant_t &)' already has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(386) : error C2084: function 'class _com_ptr_t<class _com_IIID<struct Property,&struct __s_GUID _GUID_00000503_0000_0010_8000_00aa006d2ea4> > __thiscall Properties::GetItem(const cla
ss _variant_t &)' already has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(397) : error C2084: function 'class _variant_t __thiscall Property::GetValue(void)' already has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(405) : error C2084: function 'void __thiscall Property::PutValue(const class _variant_t &)' already has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(410) : error C2084: function 'class _bstr_t __thiscall Property::GetName(void)' already has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(417) : error C2084: function 'enum DataTypeEnum __thiscall Property::GetType(void)' already has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(424) : error C2084: function 'long __thiscall Property::GetAttributes(void)' already has a body
c:\trainer\a_tr noblob indb series\trnoblob13g\release\msadox.tli(431) : error C2084: function 'void __thiscall Property::PutAttributes(long)' already has a body
C:\Trainer\A_TR NOBlob inDB series\TrNoBlob13g\Train1View.cpp(3991) : warning C4553: '==' : operator has no effect; did you intend '='?
C:\Trainer\A_TR NOBlob inDB series\TrNoBlob13g\Train1View.cpp(4449) : error C2264: 'GetCount' : error in function definition or declaration; function not called
Error executing cl.exe.
Train1.exe - 18 error(s), 9 warning(s)
I like the class but dont know how to make errors disapppear. I have #import msado25.tlb
|
|
|
|
|
Maybe it's very stupid question. I'm talking about application working on LAN. I can get IP adress but i need send a broadcast message. IMO is simplest way replace part of IP adress with 0xFF(or something like this depending on adressing of LAN) and send UDP packet. But i don't know how to get mask and find right part of adress to replace. Can anybody help me?
|
|
|
|
|
I'm not sure what you're talking about here. Mask? Anyways, if you want to send a broadcast message just set the destination IP address to 255.255.255.255 and set the port to whatever port you're going to be using. I believe most routers will block that (not routeable) so it won't go out on the Internet but remain on your LAN and probably won't cross any segments.
|
|
|
|
|
Ok, after doing some research on a related topic, I stumbled across what you were talking about. You're asking about the subnet mask.
I don't know how you get it. But, as I stated earlier you can send 255.255.255.255 as a broadcast for all subnets. If your IP address was 192.168.1.22 and your subnet mask was 255.255.255.0 then sending a broadcast message with IP address 192.168.1.255 would work also. Thus, that becomes a broadcast message for that subnet only.
The procedure I read said negate OR the subnet mask with your IP address to get that value.
e.g. ip |= ~mask to get broadcast address.
|
|
|
|
|
I have to supply documentation for the user of the app (not docs for the code). Things like features and instructions and troubleshooting etc. I'd like to make this like the help system we see that pops up with tabs for index, search, contents etc. Can you please point me to links, sample code etc on how to do this?
Thanks,
ns
|
|
|
|