|
normally, c++ calling is syncronized, here is an example:
//caller
int i;
GetInt(i);
//function
void GetInt(int&i)
{
............
i=5;
//point a
more code here
}//point b, end function
my question is, the caller gets value i=5 at point a or point b?
this question sounds silly and no interesting, but from first day of using COM to now, i don't undestand why following code works fine (thousands of times with no any trouble), see code bellow:
//COM code
void GetBSTR(BSTR*ppw)
{
BSTR str=::SysAllocString("my string in word");
*ppw=str;
//point a
::SysFreeString(str);
}//point b
the 'str' has been freed at point b, why caller has no trouble?
i know many people don't use ::SysFreeString, but anyway we should, otherwise who frees 'str'?
thx
includeh10
|
|
|
|
|
It is just pure 'luck' that it works.
(The mem is marked free but the string is still there)
/M
- Don't sweat the petty things, and don't pet the sweaty things.
|
|
|
|
|
includeh10 wrote:
i know many people don't use ::SysFreeString, but anyway we should, otherwise who frees 'str'?
No, you should not free the string. When you return data through an [out] parameter, the data belongs to the caller. Freeing it like that destroys the data before the caller gets it.
--Mike--
Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Imagine this scenario:
Mate, can I borrow your shack by the beach for the weekend?
Um, Sure. I moved out a while ago tho, and left it abandoned, so I don't know what state it's in.
Now when you go to visit, you've got 3 chances:
1) It's still there, intact (but it may fall down later)
2) It's there, but it's gone damp and is now inhabited by nasty insects and scary hobos
3) It's already been condemmed and demolished
Due to timing, you're getting to your string before the memory manager has touched it, but its memory will be marked as no longer in use, so it could get reused by something else at any moment
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
Hi,
In my application, i have draw a 2D graph with a number scatter points. Now I want select two points by left-click the mouse two
times, and then change the positions of the points between the selected points (such as move points, linearization ...). Firstly, how to select the drawed points? how to give a mark of the selected point?
Thanks in advance?
chen
|
|
|
|
|
Draw it with other color, other size - any way you want. See also MFC sample DRAWCLI - the great sample that shows graphic interface implementation. It uses PatBlt finction to mark selected objects. Remember also that standard way to select more than one object is using Ctrl key together with mouse.
|
|
|
|
|
i need to drag and drop menu items as user required.
problem is, if hold down mouse button, popup menu on menu bar will not go down anyway (if click, it goes), so i have no idea to drop a menu item to target.
really need ur help.
thx
includeh10
|
|
|
|
|
i have 2 modeless dialog boxes (in same app), on each i display some pictures (16*16 pixels) - they are just pictures by DC (not windows).
i need to drag a pic from one dialog to another. i check mouse down on which pic then start drag. then use mouse move and mouse up (set capture) for drop.
i think it is possible to have better messages instead of simple mouse events even in this case.
do u have better idea?
thx
includeh10
|
|
|
|
|
for some reasons, i need to create a CBitmap from buffer, the buffer is OK (BITMAPINFOHEADER+RGBQUADs+bitsBuf) because i display the buffer properly by StretchDibits function.
now i try to create CBitmap from it.
use CBitmap.CreateBitmapIndirect((BITMAP*)pBuf).
pBuf=BITMAP+bitsBuf. return value and size of the bitmap checked OK, but when select it into memory DC then BitBlt to client DC (all return values are OK), i see nothing.
do u know what is wrong?
and, why pBuf doesn't have color table?
Note: the CBitmat will be used in CToolBar (AddBitmap), so no DC should be involved.
thx.
includeh10
|
|
|
|
|
see CreateDIBitmap or CreateDIBSection
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
I have a pdf file. I know there exists software
out there that lets me print on top of the pdf
file. Isn't there any way of printing user
text and a pdf file together so that text is
printed on top of that file?
I can convert the pdf to a bitmap and print text
with a bitmap easily. Unfortunately, the bitmap
does'nt print clearly. Isn't there a way to
print the pdf by a dos command and before that page goes to the printer, send some text with it so that it prints together?
Please, any response any one can give me will be greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
I'm trying to have my EXE pass an WM_PAINT message to a dll with no luck. The last idea I had was to use the following
m_SpellCastingBar.SendMessage(WM_PAINT);
however this did not work as well. I have tried Invalidating the rectangle however I'm not sure if I'm even reaching the dll with this call as the WM_PAINT message is not getting retrieved by the dll.
Might there be something I am missing?
Thanks!
"Why are we hiding from the police, Daddy?"
"We use VI, son. They use Emacs."
|
|
|
|
|
You should not pass WM_PAINT messages to windows. Windows will ignore them anyway. Windows only generates paint messages itself if the message queue for that thread is empty. Even then the target window needs to have an invalid area on it window rect for a paint message to be generated. When you were looking to invalidate the rect of the window that is more along the lines of what you need to do.
If you want to force a repaint of the window use the RedrawWindow function. Here is an example.
m_SpellCastingBar.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_NOERASE | RDW_UPDATENOW);
The first two nulls indicate that you want the entire window to be updated. The flags say that you are invalidating the update region of your window because you can validate the window as well and prevent WM_PAINT messages from being called. RDW_NOERASE says do not generate a WM_ERASEBKGND message, and the RDW_UPDATENOW flag says expedite this request, and send the WM_PAINT message before the function call ends.
Coincidentally, these two function calls will do the equivalent of the RedrawWindow function above.
m_SpellCastingBar.InvalidateRect(NULL);
m_SpellCastingBar.UpdateWindow();
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
In a C++ class for a COM class, I have a method declared (which is a [out, retval] parameter):
<br />
STDMETHODIMP CSimCom::toString(BSTR *strdate)<br />
{<br />
...<br />
*strdate = cstr;
}<br />
|
|
|
|
|
*strdate = cstr.AllocSysString();
BTW, try not to use MFC in ATL projects.
You can use _bstr_t ATL wrapper class for strings, or CComBSTR.
Goodluck,
Dudi
|
|
|
|
|
Thanks ^^
but i should use MFC too, as it is using some classes in a DLL dependent in MFC. I got that from MSDN too.
|
|
|
|
|
Hello,
I am reading a file in my program that resides in the same directory as my program EXE file. When I execute the file by double clicking the file .. it works fine .. but when I execute it through the start menu icon that was created using installshield, using the follwing installshield code,
svPath = TARGETDIR ^ "TDMS2000.exe";
LongPathToQuote ( svPath , TRUE );
AddFolderIcon (FOLDER_PROGRAMS^SHELL_OBJECT_FOLDER , "TDMS2000" , svPath , "" , "" , 0 , "" , REPLACE );
It says that it could not find the text file. Please tell me what I need for it to see the file.
Thanks!
sincerely,
Anjum.
|
|
|
|
|
Can someone give me some clues on how I can do the following things, eg what sort of messages I need to be overriding.
- I have an MDI app. When the MDI frame is loaded, I load a modeless dialog box acting as a toolbox. Id like to be able to drag things from this toolbox onto the view.
- Once things are dragged onto the (CView derived) view, id like to be able to drag them around, and possibly be able to link them up, eg when i ricght click on one of the nodes a line is extended, and when this is released on top of another node, things happen in the document.
Ive never been able to get much use out of Spyy++.
|
|
|
|
|
I am trying to retrive a some data from a database,
filling a dataset,
modyfieng the data,
updating the database.
I have the gotdotnet guide on how to make this, in Managed C++:
{
// Database connection string
SqlConnection* myConnection = new SqlConnection (S" User ID=;Password=;Initial Catalog=catalog;Data Source=(local)");
// Open connection
myConnection->Open();
// SQL Query
// Create the SQL statements inserting the Username and the Password received as parameters.
String* szQuery = String::Concat("SELECT * FROM Users WHERE UserID = '", szUsername);
szQuery = String::Concat(szQuery, "' AND Password = '");
szQuery = String::Concat(szQuery, szPassword);
szQuery = String::Concat(szQuery, "'");
SqlDataAdapter* mySqlDataAdapter = new SqlDataAdapter(szQuery, myConnection);
DataSet* myDataSet = new DataSet();
mySqlDataAdapter->MissingSchemaAction = MissingSchemaAction::AddWithKey;
mySqlDataAdapter->Fill(myDataSet, "Locals");
DataRow* myDataRow = myDataSet->Tables->Item["Locals"]->Rows->Item[0]["ContactName"]="Peach"; //this line gives error C2107
SqlCommandBuilder* mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);
mySqlDataAdapter->Update(myDataSet,"Locals");
}
but the line where i try to modify the data in the DataRow gives the error: error C2107: illegal index, indirection not allowed
How I fix it please?
P.S.
I cannot access it through the Find method, because I am not able to know the value of the primary key to research.
"Nelle cose del mondo non e' il sapere ma il volere che puo'."
|
|
|
|
|
Is there any differece between OnDraw or OnPaint functions?
Where should custom drawing should be implemented?
|
|
|
|
|
Rules
CView based classes use OnDraw,
General CWnd based classes use OnPaint
Custom OwnerDraw should use OnDrawItem
Normski. - the next bit of code is self modifying ... jmp 0xCODE
|
|
|
|
|
|
Customdraw an ownerdraw is 2 different things.
Customdraw is handled in response to WM_CUSTOMDRAW
/M
- Don't sweat the petty things, and don't pet the sweaty things.
|
|
|
|
|
Hi,
I am looking at rewritting a routine, where each line reference an object.
pObj->method1
pObj->method2
pObj->method3
pObj->method4
Is there any way of eliminating the need to specify the object, bit like that Pascal and VB with statement.
Cheers
Rich
|
|
|
|
|
You can return 'this' pointer from each method and then you will get:
pObj->method1()
->method2()
->method3()
->method4();
|
|
|
|
|