|
I have a class ParticleExplosion which has a member function void update() :
class ParticleExplosion {
public:
void update();
};
...and a vector of pointers to ParticleExplosion objects
vector< ParticleExplosion * > explosions;
Here, I the iterator I need, set it equal to the first item in the vector, then step through the vector, calling ParticleExplosion::update() every time...
std::vector< ParticleExplosion * >::iterator vItr;
vItr = explosions.begin();
while( vItr != explosions.end() )
{
vItr->update();
++vItr;
}
But, I get this error:
left of '->update' must point to class/struct/union
I've also tried this with:
*vItr->update();
**vItr->update();
*vItr.update();
**vItr.update();
...just in case *something* would work.
So, my question is: what is the correct to dereferencing the vector iterator correctly, so that I can access the object member functions?
|
|
|
|
|
(*iter)->method()
Some STL implementations allow you to write iter->method() but Microsoft's is not one of them, IIRC.
|
|
|
|
|
This is a common enough gotcha that I thought this was what you were asking about when I saw the header. You need to do this:
(*vItr)->update();
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
|
Hi,
I posted a message to a thread in another class and found that paramters wrapped in wParam turned out to be an empty data struct.
the precondition is: I had used "new" to create parameters wrapped in wParam before posting.
Any Example to illustrate ur opinion is appreciated.
Thanks in advance
Extreme programming. Do the No.1
|
|
|
|
|
from inside a dialog box in an MDI app
void CDlgbtnChart::OnOK() <br />
{ <br />
UpdateData();<br />
UpdateData ( FALSE );<br />
m_SingleSpan;<br />
<br />
Chart(m_DFile, m_LFile, m_PathName", m_SS, true, true );<br />
<br />
// Is this the correct way to open the file into the editor?<br />
CMultiDocTemplate* pDoc;<br />
pDoc = new CMultiDocTemplate(IDR_PLUTOTYPE,<br />
RUNTIME_CLASS(CPlutoDoc),<br />
RUNTIME_CLASS(CChildFrame),<br />
RUNTIME_CLASS(CPlutoView));<br />
pDoc->OpenDocumentFile(m_sPathName);<br />
<br />
CDialog::OnOK();<br />
}
"Democracy is two wolves and a lamb voting on what to have for lunch.
Liberty is a well-armed lamb contesting the vote."
Ben Franklin - 1759
|
|
|
|
|
kjessee wrote:
UpdateData ( FALSE );
This does nothing - you did not change the variables, so why shove them back up into controls you're about to destroy ?
kjessee wrote:
m_SingleSpan;
Is there some code inside <> missing here ?
kjessee wrote:
// Is this the correct way to open the file into the editor?
It's the wrong spot - the dialog should not be responsible for opening a document, I'd be doing it when the dialog closes, if the return value is IDOK. I believe that the mainframe also has methods for opening a new file, which do all this for you, but I could be wrong.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
I took out some code to make it easier to read.
|
|
|
|
|
article referece: (http://www.codeproject.com/asp/cookie.asp)
Two Questions:
QUESTION 1: method, input/output parameters and return
method prototype: STDMETHODIMP CCookiesCtrl::GetCookie(BSTR *bVal)
Note that it takes ONE input parameter between the bracket - bVal.
QUOTE from article "Type GetCookie for Method Name and [out,retval] BSTR *bVal for parameter."
ASP call:
str=obj.GetCookie()
What da..? shouldnt GetCookie take one parameter, and what's the return type anyway? what's STDMETHODIMP? Can u pass variable by reference/by value? And what about custom data type/struct/class?
QUESTION 2:
is there anywhere i can check "progID" besides "ATL Object Wizard Properties>Name"??
Thanks!
norm
|
|
|
|
|
OK. First of all, when you define your COM function, your IDL ( which defines the interface ) can specifify a parameter as IN or OUT. An OUT is a returned value and must be a pointer. The last parameter can also be OUT, RETVAL, which means in script, because the HRESULT is not returned, the parameter is instead.
Secondly, Javascript typically does not require you to specify the return type - that is why a JScript function always has 'function' next to the name, not a return type. The return type is whatever type you put next to the word 'return'.
STDMETHODIMP is a macro that basically just makes the return type a HRESULT, as they are for all COM calls. You are also limited in what you can pass in, basically I think anything you can shove into a VARIANT can be passed into a function. No custom structs or classes, you can pass an enum value though. ( that's just a number anyhow ).
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Q1. [out,retval]
Languages like VB (and friends) handles the "real" returnvalue from the function (a HRESULT) "under the hood" and returns the retval parameter instead to the caller.
The C++ way of doing this would have been to throw an exception but C++ exceptions are not allowed to leave a COM function. (This also applies to "properties" which in C++ is mapped into 2 functions, put_ & get_ usually).
Instead the the parameter is passed by reference and marked as an out-parameter in the IDL.
By using the #import directive without any options you get wrappers for the objects that WILL generate exceptions, com_errror, but I prefer doing it raw
Q2. progID
From the top of my head, in the projects .rgs file.
I'm too tired to remember (and far too tired to check) but it might also be present in the .idl file...
[edit]
Ops, forgot... The STDMETHODIMP also specifices the calling convention of the function, i.e. HOW parameters are passed in and out and who is responsible for the mess afterwards
[/edit]
|
|
|
|
|
yes, it's in rgs file i supposed.
HKCR
{
SimpleActiveX.CookiesCtrl.1 = s 'CookiesCtrl Class'
{
CLSID = s '{11E3E9EA-84B4-4E80-9639-6148F608E5AD}'
}
SimpleActiveX.CookiesCtrl = s 'CookiesCtrl Class'
{
CLSID = s '{11E3E9EA-84B4-4E80-9639-6148F608E5AD}'
CurVer = s 'SimpleActiveX.CookiesCtrl.1'
}
NoRemove CLSID
{
ForceRemove {11E3E9EA-84B4-4E80-9639-6148F608E5AD} = s 'CookiesCtrl Class'
{
ProgID = s 'SimpleActiveX.CookiesCtrl.1'
VersionIndependentProgID = s 'SimpleActiveX.CookiesCtrl'
ForceRemove 'Programmable'
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Both'
}
'TypeLib' = s '{36E65AC9-E595-4B7F-B7AB-0551CE8E87F3}'
}
}
}
But I keep getting the following error... I thought i solved this problem...
Error Type:
Server object, ASP 0177 (0x800401F3)
Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.
/MyCookiesServ.asp, line 2
Someone suggested that i should installed service pack 5 for visual studio.. i downloaded the patch, but think the package is corrupted. i read the related technical articles, i cant find any relation between SP5 and ATL-COM. so, i gave up on installing SP5..
Anyway, here's the ASP script:
<%
Set obj=Server.CreateObject("SimpleActiveX.CookiesCtrl.1") //THIS IS THE LINE THAT'S CAUSING PROBLEM...
str=obj.GetCookie()
%>
<title>
Test ActiveX Server Component
The cookie stored is "<%=str%>"
Hope someone can safe my sorry ass and point me to the right direction.. .I compiled the code sample i downloaded from http://www.codeproject.com/asp/cookie.asp...
it compiled, and i tested the asp page and it (sample i downloaded) worked... so it must be something i did wrong along the way...
norm
|
|
|
|
|
Ok, long time no ASP but...
1. Did library register correctly? Verify with regsvr32 <filename>
2. Is the typelibrary needed and if so is it compiled and registered?
Merged or separate?
|
|
|
|
|
thanks for the feedback. I've got my server properly registered.
it's a simple method that add two numbers:
STDMETHODIMP CATLStringParser::AddTwoNum(long Num1, long Num2, long *ReturnVal)
{
// TODO: Add your implementation code here
*ReturnVal = Num1 + Num2;
return S_OK;
}
But i am not sure how to make the ASP call:
<%
Set obj=Server.CreateObject("StringParser.ATLStringParser")
some_num = obj.AddTwoNum(10, 2) //PROBLEM HERE!
%>
<title>
Test simple ATL ActiveX control server.
... some processing ...
For some reason, I keep getting:
Error Type:
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment: 'obj.AddTwoNum'
/MyCookiesServ.asp, line 3
I've tried a few things already:
some_num = obj.AddTwoNum(10, 2)
obj.AddTwoNum(10, 2, some_num)
none worked. Help!
norm
|
|
|
|
|
Okay, now I've done it. Not sure what, but hopefully some one here has some suggestions. I'm using version 6 on NT 4, btw, and have VSS integrated. Everything works perfect except when I use my network login. Other people login to the machine, and the program runs fine and loads any and all projects perfectly. If I use the local administrator account, again all works fine. But when I use my own account, msdev.exe brings up a Dr. Watson while the splash screen is still being displayed. I suspect that there must be some special registry settings that are user specific that are causing the problem, but I can't seem to locate the one causing this problem. I welcome any sugggestions from those with more registry knowledge.
I think I started this problem by executing the debug version of a program by double clicking it from an open explorer window. While this was running, I then tried to start up msdev and it would have attempted to load the workspace that contained the project that builds the executable that I was already running. This produced the very first crash. Even after power off's and restarting, it continues to crash, but only when I logon using the id that I was logged on as when the first crash occurred.
Thanks for any hints.
Chris Meech
[EDIT]
I finally found a registry entry
HKEY_USERS\..GUID-for-me..\Software\Microsoft\Devstudio\6.0
that I renamed to 'keepthis'. Following this, msdev would no longer crash. Now for the kicker. A new entry called 6.0 was created, which I promptly renamed, and the entry called 'keepthis' was now renamed back to 6.0! I was expecting msdev to now crash, but it didn't and it is now working like a champ and I have all my preferences, etc. all set as usual. Go figure.
[/EDIT]
|
|
|
|
|
Does it crash even when not loading up that particular workspace? Is so then I think you are looking at a re-install
Cheers
James
|
|
|
|
|
That's correct. When I even try to open other projects or workspaces, it still crashes. The most unusual thing though is that it all functions fine, when I login as some other user. I'm still going to do some more registry hunting before I do a re-install.
Thanks.
Chris Meech
|
|
|
|
|
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
... // all the window initializations
wndclass.hInstance = hInstance;
...
hInst = hInstance // global handle to instance
...
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
...
WM_CREATE:
LoadIcon(hInst, MAKEINTRESOURCE(IDC_REEL));
...
return 0;
...
The icon will load in every other place in the program except for WM_CREATE (The only place where I need it to load so I can place it on a button)
I get the error: 1813 (The specified resource type cannot be found in the image file.) Even though it exists because I can load it everywhere else...what am I doing wrong here, please someone I need help!
|
|
|
|
|
I don't really see the problem with the code. Perhaps a misspelling: IDC_ instead of (more common) IDI_? Have you tried passing NULL instead of hInst (assuming IDC_REED resides in the main exe)?
I assume the CreateWindow of the main window is called after the line hInst = hInstance; .
/moliate
The corners of my eyes catch hasty, bloodless motion -
a mouse?
Well, certainly a peripheral of some kind.
Neil Gaiman - Cold Colours
|
|
|
|
|
Thank YOU!!!!!!!! I had hInst = hInstance after CreateWindow was called...can you explain to me why it works when put before and not after?
|
|
|
|
|
One of the first tasks CreateWindow do is putting a WM_CREATE message on the queue. This means you probably call LoadIcon in the messagepump before hInst is set to a valid value - it could be anything...
Cheers
/moliate
The corners of my eyes catch hasty, bloodless motion -
a mouse?
Well, certainly a peripheral of some kind.
Neil Gaiman - Cold Colours
|
|
|
|
|
I struct a frustrating problem.
An application that is now in its 7th version and has never exhibited this problem before has suddenly decide to hide behind visual studio if launched from there or explorer if launched from there. Also the taskbar flashes indicating it is inactive.
No changes have been in either the Application's InitInstance or the Create and PreCreateWindow functions of the Main Frame. It is of cause obvious that something has changed in the project somewhere.
Any suggestions as to where I can look will be welcome. The problem seems to 'worst' on XP.
|
|
|
|
|
I'm having a problem deleting objects I've created with the new operator. I have two classes: Particle and ParticleExplosion. ParticleExplosion has:
vector< Particle * > pL
Inside the constructor to the ParticleExplosion class, I make a whole bunch of Particles and put pointers to them in a vector ( pL ):
ParticleExplosion::ParticleExplosion()
{
for( i = 0; i < this->numParticles; ++i )
{
p = new Particle;
pL.push_back( p ); // pL is a vector
}
}
When a ParticleExplosion object gets destroyed (by going out of scope), it's not taking the objects the pL points to with it (which I expected). So, I made my own destructor for ParticleExplosion, where I step through the vector, and delete each item that it poitns to:
ParticleExplosion::~ParticleExplosion()
{
for( int i = pL.size(); i > 0; --i)
{
delete this->pL[i]
}
}
After deleting the first item, the program crashes. Am I going about this the right way?
daniel@jurnove.net
|
|
|
|
|
Why this->pL[i], instead of just pL[i] ? I'd use an iterator to do this, rather than a loop, but I don't think that matters. Actually, I have a functor that I call with for_each that just deletes the pointers in a vector.
I don't see what the problem is, but I'd suggest ditching this - maybe the compiler can't handle this in a destructor.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
You need to delete each member like :
class MyClass
{
public:
MyClass();
~MyClass();
int m_iIndex;
};
std::vector<MyClass*> myClassVector;
for (int i = 0 ; i < 10; i++ )
{
MyClass* p = new MyClass();
myClassVector.push_back(p);
}
std::vector<MyClass*>::iterator it = myClassVector.begin();
while ( it != myClassVector.end() )
{
delete (*it);
++it;
}
Max.
|
|
|
|
|