|
Well, last night sometime after i got off the net i had a revelation on how to do it, sat down and in 15 minutes i had it. it works quite good too, i owuld post it it but uses two other functions i made, and they other functions, so i would end up having to post my entire header file that im making.
|
|
|
|
|
(Sorry for the spam, but here's a proper version without the <> getting eaten.)
I'm trying to store boost::shared_ptrs in a std::map with a const std::string as the key.
The trouble arises when I need to find a value. Using find() yields an iterator, but VC2003 doesn't like it:
error C2440: 'initializing' : cannot convert from 'std::allocator<_Ty>::value_type' to 'boost::shared_ptr<T>'
with
[
_Ty=std::pair<const std::string,boost::shared_ptr<Sprite>>
]
and
[
T=Sprite
]
And here's the bit of code that causes this reaction:
map<const string, shared_ptr<Sprite> >::iterator frameSet = mysprite.find("animationName");
What I had hoped was that frameSet would be an iterator that I could dereference to call member functions on the Sprite object. But, alas.
Anyone have any suggestions?
tentons
|
|
|
|
|
I'm trying to store boost::shared_ptrs in a std::map with a const std::string as the key.
The trouble arises when I need to find a value. Using find() yields an iterator, but VC2003 doesn't like it:
error C2440: 'initializing' : cannot convert from 'std::allocator<_Ty>::value_type' to 'boost::shared_ptr<t>'
with
[
_Ty=std::pair<const std::string,boost::shared_ptr<sprite="">>
]
and
[
T=Sprite
]
And here's the bit of code that causes this reaction:
map<const string,="" shared_ptr<sprite=""> >::iterator frameSet = mysprite.find("animationName");
What I had hoped was that frameSet would be an iterator that I could dereference to call member functions on the Sprite object. But, alas.
Anyone have any suggestions?
tentons
|
|
|
|
|
OK, I've been playing with C++ (for windows apps) only for about a week now. What I'm trying to do is create a toolbar in my main (and only) window. Now I can do that, but I want to use a toolbar I've created in the Resource Editor in MSVC++ 6.0, and just can't seem to figure out how to implement it from there instead of creating it from scratch. I've tried google and MSDN, any help would be appreciated.
I'm not using MFC, so I've been calling CreateWindowEx(...) to create the toolbar.
Thanks =oP
Ian
|
|
|
|
|
Posting your problem twice will not get you any more answers or a quicker response. Be patient.
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Dear programmers,
I'm accessing an Excel object and trying to manipulate it.
I'm having trouble copying a worksheet in VC++ (MFC).
So far, some function that i've used was working fine except the copy function of Worksheet class. There's no error during compilation, but at runtime a message is displayed stating that "Copy method of worksheet class failed."
Please help me with this one ...
By the way, I am using MS Office 2000.
Thanks in advance.
|
|
|
|
|
I assume this is a debug message or an exception/run-time error message you're getting ?
In that case, you should check the actual worksheet. Is it locked ? Do you have priviledges to read/modify it ? Protected by a password ?
Last option is to use the debug mode to step through the code, and see if a function returns an errorneus value or receives an incorrect parameter.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I already set the worksheets property accordingly.
I also step through the code in debug mode, but I could not understand the return values of the function, it shift to a different source file.
Here's a sample of my code...
<br />
_Application appExcel;<br />
Workbooks books;<br />
_Workbook book;<br />
Worksheets sheets;<br />
_Worksheet sheet;<br />
Range range;<br />
<br />
<br />
if( !appExcel.CreateDispatch( "Excel.Application" ) )<br />
{<br />
AfxMessageBox( "Excel couldn't start." );
return ;<br />
}<br />
appExcel.SetVisible( FALSE );<br />
<br />
COleVariant UpdateLinks( ( long ) TRUE, VT_BOOL ), <br />
ReadOnly( ( long ) FALSE, VT_BOOL ),<br />
Format ( ( long ) TRUE, VT_BOOL ),<br />
Password( ( long ) FALSE, VT_BOOL ),<br />
WriteResPassword( ( long ) FALSE, VT_BOOL ),<br />
IgnoreReadOnlyRecommended( ( long ) FALSE, VT_BOOL ),<br />
Origin ( ( short ) 2 ),<br />
Delimiter( ( long ) FALSE, VT_BOOL ), <br />
Editable ( ( long ) FALSE, VT_BOOL ), <br />
Notify ( ( long ) FALSE, VT_BOOL ), <br />
Converter( ( long ) FALSE, VT_BOOL ), <br />
AddToMru ( ( long ) TRUE, VT_BOOL ); <br />
<br />
books = appExcel.GetWorkbooks( );<br />
book = books.Open( m_strReportPath, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, <br />
IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMru );<br />
<br />
sheets = book.GetSheets( );<br />
sheet = sheets.GetItem( COleVariant( ( short ) 2 ) );<br />
<br />
COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);<br />
sheet.Activate( );<br />
sheets.Copy( COleVariant( (short) 2), COleVariant( (short) 1));<br />
<br />
book.Save( ); <br />
books.Close( );<br />
appExcel.Quit( );<br />
|
|
|
|
|
Why does code like this sometimes result in a compiler error?
mpGlobalQueue->mPushQueue(::GEOSIT_IN, NULL, ::SHUTDOWN);
GEOSIT_IN and SHUTDOWN are perfectly valid constants that exist in the global name space. I can use :: to identify global functions within classes, which is very helpful when reading code. But many times when I try to identify constants as global, in this way the compiler gives me errors like the following:
error C2589: 'constant' : illegal token on right side of '::'
|
|
|
|
|
This is most often caused by a compiler misunderstanding the context. Another reason for it might be a syntax error earlier in the file. Although what you've written right there is correct, the compiler doesn't quite get it.
Try using a space between the opening parenthesis and the first constant. Another trick is to encapsulate the constant into parenthesis' of its own. This forces the compiler to first evaluate the constant value, and then supply it as a parameter to the function. In this case, the compiler (perhaps) thinks that GEOSIT_IN is a member of mpGlobalQueue , which I presume to be an object, struct or union. This causes the error.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks for the tip. That is what I thought as well, however even after supplying the parenthesis around the constants, the same error was reported by the compiler. The rest of the code compiles fine and only when I remove the usage of the global scope operator does visual studio compile completely.
|
|
|
|
|
you cannot use :: operator for constants defined using #define. It can be used only for declared identifiers. Look the following code
#define CONSTANT1 100<br />
<br />
const int CONSTANT2 = 100;<br />
<br />
main()<br />
{<br />
<br />
cout << ::CONSTANT1;
cout << " " << ::CONSTANT2;
}
|
|
|
|
|
Oh. That would be the problem. I did not know that. Thank you.
Shawn
|
|
|
|
|
How can I set a hook on a certain window fucntion like RegCreateKey for example because I want to design a firewall that looks over the registry.
To set the hook on a ceratin fucntion and my function should be called firts befeore that certain function is called
gabby
|
|
|
|
|
http://www.codeproject.com/system/hooksys.asp
http://www.codeproject.com/dll/apihijack.asp
There you go
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
I want to learn more on c++ & java scripting and how all this plays out in the MMROPG industry. As I have been reading more and more daily on this i feel that I am progressing and as I read a book from John Smiley (Learn C++) I'm not sure if that is the actual title but hey when I'm stuck in the Seattle Traffic, I can pop a few pages into my memory bank.
I would like to know if someone can lead me in the right direction as to what, where or who I need to talk too, also as my research has compiled I have found I am in need of SoftICE, WDASM, x86 ASM and DHack, Note Pad, WPE Pro, to do what they call packet handling on these servers, as I have know clue what or where to start on all that. I ask for some experienced guidance in this aspect and explaination of what SoftIce, WDASM, x86 ASM and WPE Pro is and if there is a simplier method please feel free to leave something here in the forum and I will check back daily.
Thanks
Jimmy
|
|
|
|
|
mztrjimmy wrote:
I would like to know if someone can lead me in the right direction as to what, where or who I need to talk too
Start slowly.
SoftICE and the other tools are fairly 'Hard Core' types of things that you don't want to mess around with unless you have to because of the steep learning curve. My suggestion is that Microsoft Visual Studio is the easiest way to get started in most languages - especially compared to notepad.
Scripting
Scripting is a great way to get started with modding games, neverwinter nights and unreal tournament both have scripting system that have been used extensively.
Learn the syntax of one major language.
C++ is a great place to start, but C# and java are IMO slightly easier to get started with, if you get really serious then you'll probably come back to c++ eventually anyway.
Learn the basics of win32 programming.
The easiest way to get started is MFC, when you feel comfortable with MFC try the raw win32 API. Also, don't neglect the operating system fundamentals like sockets and threads - apart from being useful in general they form the backbone of almost all server applications.
Who to talk to?
Game Programming
http://www.flipcode.com[^]
http://www.gamedev.net[^]
Windows / MFC
Here of course!
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
I really have to say thanks alot and I do have to say that I do have one thing, is that I have Microsoft Visual Studio .net and slim resources on where to learn MFC. If anything there that you could lead me too that would be greatly appreciated.
Jimmy
|
|
|
|
|
Okay, here is a long-winded post, so bear with me.
I am in midst of writing a real-time data monitoring program using Visual C++ .NET (originally started out in VC++ 6 - only upgraded in the past couple months).
Anyway, the program includes a plot view showing points representing data collected at a given time. The plot view is a heavily modified version of Mark C. Malburg's OScope/Strip Chart control cribbed from this very site (http://www.codeproject.com/miscctrl/oscope.asp).
One of the major modifications is the ability to "pause/play", "rewind", and "fast-forward" the plot using a set of VCR-style button controls (with the typical "||", ">>", and "<<" type symbology) and a slider. Along with the ability to pause the plot is the ability to select and highlight the points in the plot (now THAT was fun to implement! ). As a result, I am now implementing the ability for the user to right-click on a point in the plot to view the actual data. Since it is possible that more than one "data item" can be represented by a single point in the plot (it is at one-second granularity), I need the ability to dynamically generate the pop-up menu, with each menu item represented as a single data item to examine.
This is what I have so far:
In the function "OnContextMenu" in the CPlotView class:
// Convert the point where the right-click occurs
// to client coordinates
::ScreenToClient (this->m_hWnd, &clClickPoint);
// Setup a vector that will contain all the
// data points found at the coordinates of the
// right-click
CStripChartCtrl::pclDataPointVec pclDataPointsVec;
// Populate the vector to contain all the
// data points found at the place where the
// user right-clicked in the plot.
m_clStripChart.vGetDataPoint (clClickPoint, pclDataPointsVec);
// Check if the vector is empty (which would
// indicate no points found were the user
// right-clicked (a blank area of the plot,
// for example).
if (pclDataPointsVec.empty () == false)
{
// code to highlight the points (removed
// for brevity sake - basically just
// passed the data vector to a vHighlight
// method of the strip chart control class)
// Dynamically setup the menu showing the
// selectable data items.
CMenu clDataMenu;
vSetupViewDataMenu (pclDataPointsVec, clDataMenu);
// Append the data sub-menu to the
// menu loaded from resource under the
// "view data" option
HMENU hDataMenu = clDataMenu.Detach ();
clPopupMenu.AppendMenu (MF_STRING | MF_POPUP | MF_ENABLED, (UINT)hDataMenu, "View Data");
}
else
{
// if no data items found, then simply add
// a greyed out "view data" option
::GetCursorPos(&clMenuPoint);
clPopupMenu.AppendMenu (MF_STRING | MF_GRAYED, 0, "View Data");
}
// Code follows to setup and then make the menu appear using the "TrackPopupMenu" method of the clPopupMenu object.
The function "vSetupViewDataMenu" appears below in its entirty. Basically, it loops through the passed in data vector and "sorts" them by event type (which is represented by letters - future enhancement is to actually give them a name, but this program is still in its very early alpha/prototype stage). It then loops through the "sort" map and builds the cascading "view data" menus, the first level by event/data type, followed by an entry for each data item. As the menu is being built, each item is put into a map, indexed by menu ID (starting with "ID_PLOT_VIEWDATA"), so that the program will know which piece of data is represted by each menu item.
//--------------------------------------
void
CPlotView::vSetupViewDataMenu (
CStripChartCtrl::pclDataPointVec &pclDataVec,
CMenu &clMenu)
//--------------------------------------
// Description:
// This private function will dynamically
// setup the pop-up menu item to allow
// the user to view the data for the
// selected point.
//--------------------------------------
{
map<char, vector <CDataPoint *> > clDataMenuMap;
map<char, vector <CDataPoint *> >::iterator clDataMenuIter;
clMenu.CreatePopupMenu ();
m_pclMenuDataMap.clear ();
// loop through the passed in data vector
for (UINT i = 0 ; i < pclDataVec.size (); i++)
{
char cLetter = pclDataVec[i]->cGetPointChar();
clDataMenuMap[cLetter].push_back(pclDataVec[i]);
} // end for loop vector
// Now, iterate through the menu map and add each of the submenus
// into the passed in menu object
UINT uiMenuID = ID_PLOT_VIEWDATA;
for (clDataMenuIter = clDataMenuMap.begin ();
clDataMenuIter != clDataMenuMap.end ();
clDataMenuIter++ )
{
CString strMenuItem;
if (clDataMenuIter->first == 0)
strMenuItem = "View EP Information";
else
strMenuItem.Format ("View Event Type -> '%c'", clDataMenuIter->first);
CMenu clSubMenu;
clSubMenu.CreatePopupMenu ();
for (UINT i = 0; i < clDataMenuIter->second.size(); i++)
{
CString strSubItem;
strSubItem.Format ("Data Item %d", (i + 1));
clSubMenu.AppendMenu (MF_STRING | MF_ENABLED, uiMenuID, (LPCTSTR)strSubItem);
m_pclMenuDataMap[uiMenuID] = clDataMenuIter->second[i];
uiMenuID++;
}
// Detach the newly created sub-menu from the CMenu class and
// then append it to the passed in menu class
HMENU hSubMenu = clSubMenu.Detach ();
clMenu.AppendMenu (MF_STRING | MF_POPUP | MF_ENABLED, (UINT)(hSubMenu), (LPCTSTR)strMenuItem);
} // end for loop map
} // end private function vSetupViewDataMenu
Since there is no message map generated for this, I was going to override the "OnCmdMsg" as shown below. Right now, I was going to have the program simply display a message box to indicate that an item was succesfully selected and found (before getting into the technicalities of the actual data retrieval - that is whole 'nother topic with this program - yeesh! This program is to process many megabytes of data per SECOND, thus all kinds of crazy caching schemes and storing to temp files and such in an effort to make it efficient in both memory and speed as possible)
This is what I currently have in the "OnCmdMsg" function:
//--------------------------------------
BOOL
CPlotView::OnCmdMsg(
UINT nID,
int nCode,
void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo)
//--------------------------------------
// Description:
// This function handles the command messages
// that are sent when the user selects an
// item from the dynamically built view
// data menus.
//--------------------------------------
{
// TODO: Add your specialized code here and/or call the base class
if (pHandlerInfo == NULL)
{
if ( (nID >= ID_PLOT_VIEWDATA) &&
(nID < ID_PLOT_VIEWDATA +
m_pclMenuDataMap.size ()) )
{
if (nCode == CN_COMMAND)
{
CString strMessage;
strMessage.Format ("Selected Menu Item: %d", nID);
AfxMessageBox ((LPCTSTR)strMessage);
}
else if (nCode == CN_UPDATE_COMMAND_UI)
{
CCmdUI* pCmdUI = (CCmdUI*)pExtra;
pCmdUI->Enable (TRUE);
}
return TRUE;
}
}
return CFormView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
After all that, the problem is that all of the items in the sub-menus appear as greyed out. I tried several things such as using the ON_COMMAND_RANGE macro in a message map (with a block of command ID's 1000 apart, since it is very unlikely there will be that many data items represtented by one plot point in realistic usage), and no such luck. I determined it is because all those ID's are not part of the resources of this application, thus Windows does not "know" about them, since they are generated at run time. How can I get Windows to recognize those ID's at runtime, thus enabling those dynamically added menu items so the user can click on them?
When Windows won't do it, use Unix!
|
|
|
|
|
skonopa wrote:
After all that, the problem is that all of the items in the sub-menus appear as greyed out.
That is an MFC feature, menu items and toolbar buttons that don't have associated handlers are disabled. You can set the m_bAutoMenuEnable member of your main frame to FALSE to turn off this feature.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Actual sign at the laundromat I go to: "No tinting or dying."
|
|
|
|
|
Thank you very much! That seemed to do the trick! Now, just to get it to actually handle the message is another story.
Chalk another one up to good'ol Code Project! Only if you guys know how often this site has saved my @$$. It has been long quest for this old-time Unix developer to learn and develop programs under Windows.
|
|
|
|
|
Hi all,
so im writing a program that install itself as a process, to do this I need the path to process that is running, because my code installs the running process as the service.
Problem:
I cant seem to figure out a way to get the path the running process.
If I call GetCurrentDirectory, it will give me the directory from where the process was run which may not necessarily be the path to the process. furthermore it doesnt include the name of the executable in the path.
Also if I use argv[0], it will only work if I refer to the full path of the executable, which I dont always want to do!
Can someone help me find a way to find the path at which my process is running so that I can use that path to register the running process as a service?
|
|
|
|
|
|
Using MFC:
<br />
CFile file;<br />
file.Open(_T("."),CFile::modeRead);<br />
<br />
MessageBox(file.GetFilePath());<br />
<br />
file.Close();<br />
Ivan Cachicatari
www.latindevelopers.com
|
|
|
|
|