|
1.Initialize your object
CComObject<CYourBaseClass>* pConnection;
...
pConnection->AddRef();
return pConnections;
2.Returning a pointer cuases very much a memory leak UNLESS you destroy it in your caller function
CComObject<CYourBaseClass> *pConnection = GetGroupConnections(...);
pConnection->...
pConnection->Release();
Peter Molnar
|
|
|
|
|
So, I can do directly ?
<br />
CComObject<CYourBaseClass>* pConnection;<br />
<br />
pConnection->AddRef();<br />
<br />
return pConnections; <br />
And I don't have to call "CreateInstance" ?
If I want to return my object as an interface( e.g. a list of users that matches a certain criteria), so the collection will not be hold as a member variable, can I use ?
<br />
get_Connection(IConnection **pVal)<br />
{<br />
CComObject<CYourBaseClass>* pConnection;<br />
<br />
pConnection->AddRef();<br />
<br />
return pConnections->QueryInterface(...)<br />
}<br />
And then in the client code retrieve that value with an smart pointer ?
<br />
IConnectionPtr pConn = pMyComObject->Connection;<br />
So with the smart pointer, the object will be released automatically ?
Thanks in advance, greetings
Braulio
|
|
|
|
|
You have very much to call CreateInstance, which I ment to indicate with ... (dots) in my code. Since it was OK in yours, I didn' repeated it again, modify your get_Connection function accordingly. AddRef tells the object that there will be one more call on it, it should not unload itself, and Release tells that the call have already taken place, it can unload.
So after you received the interface pointer,you should release it. Smart pointers indeed eliminate this, because they call AddRef on object creation and Release on when the object goes out of scope.
Peter Molnar
|
|
|
|
|
Hi all,
i have a problem using the system or _exec functions when i try to load an external executable file from my code:
if i use:
system("C://myfolder//converter.exe JONNY.FFT BAGONKY.TXT");
my converter work fine and i find my output file in the "Debug" folder of my project.
if i use:
system("C://Documents and settings//converter.exe JONNY.FFT BAGONKY.TXT");
i don't find anything!!!!
How can i resolve this problem?
|
|
|
|
|
|
dukeleto wrote: my converter work fine and i find my output file in the "Debug" folder of my project.
Which indicates that the current working directory (CWD) is being used.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Dear all,
Can I trap when Windows TaskManager kill me?
Best Regards,
kglau
|
|
|
|
|
On older Windows operating systems, the TaskManager first attempts to send a WM_DESTROY message to the thread's main window, and if it fails, it will attempt to terminate the thread itself. This can be trapped by utilizing simple thread-messaging maps. See MSDN for information about threads and thread messages.
On newer operating systems (2000 and above), the TaskManager will always kill the virtual machine that is running the process that is hang. Hooking this would require some extensive API knowledge and a system wide-hook for trapping low-level kernel operations.
However, I wouldn't suggest that you even attempt to hook the operation, as the TaskManager's process-killing feature is supposed to exist and work properly on every Windows platform to end processes that are hung, acting incorrectly or are not desired.
Overriding the default behaviour would quickly result in users having malicious processes like viruses, torjans or advertising/spying software that cannot be killed without using Safe mode and delicate deletion methods. Find some other way to accomplish whatever it is you are trying to do.
If you are attempting to write a virus/trojan or advertising/spying software, then this is a wrong place to ask. We are coders of honor and respect for our jobs. Our software is made to be enjoyable and useful, not to harass people or hinder users.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi,
Of course I am not writing a virus/trojan, because writing program is my job, I am also respect
for my job too.
Thanks anyway..
KG
|
|
|
|
|
I have visual studio.net and making a database project with access. But some query runs under access and visual studio.net but same have problem under visual studio.net
and successfully runs under access. I am conneting using ODBC: Microsoft Access driver.
|
|
|
|
|
Is it because your ODBC doesn't support some SQL version?
(in MSDN)
The following SQL-92 features are not supported by Microsoft Jet SQL(the one Access ODBC was using usually):
Security statements, such as GRANT and LOCK.
DISTINCT with aggregate function references.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Hi,
Iam trying to incorporate the kodak image edit activex control in my vc++ dialog based application...can anyone help me out in how to use this control ....
Any help would be highly appreciated.
Thanking you
Satadru
|
|
|
|
|
Hi,
My application should do something like this. When I click a menu item, a dialog is displayed and after entering values and clicking OK, the entered values are displayed in the view. I have done so far.
Now after invoking the dialog, filling the values and clicking OK, I need these values to be displayed in a new frame. How do I go about doing this?
With regards
|
|
|
|
|
try this;
add code in onOK()
{
CNewFrame nf;
nf.m_XXX = yourValue;
nf.domodel();
}
Happy Gemini
|
|
|
|
|
This would mean, CNewFrame is a Dialog. I want to have a frame. Is this possible
|
|
|
|
|
I assume here that you have a SDI application, which consists of a frame window with menu and one view.
When you dismiss the dialog, you can get the necessary data values either by accessing them directly using GetDlgItem or by using the DDX system. Now, if you wish to create a new frame window, then you need to derive two new classes: one from CFrameWnd and one from CView. The frame window is created, and when created, it creates one view for itself.
After this, you can write your stuff into the view by using TextOut functions as necessary.
If you are developing an MDI application, you only need to derive a class from CMDIChild. Then create a new child window, specify the MDI frame window as parent, and use TextOut functions to output text into the child window.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I am using an MDI application. But how do I specify the MDI Frame Window as parent. I am not very clear on this part.
Do get back..
WIth regards
|
|
|
|
|
You MDI application consists minimally of following classes:
CMDIApp - This is your main application class, it is derived from CWinApp class.
CMDIFrame - This is your application's main window, a MDI Frame window. It is derived from CMDIFrameWnd class.
CMDIChild - This is one of your MDI child windows. They are derived from CMDIChildWnd class.
When you create new MDI child windows, you first construct their representative objects by either adding a static variable or using the new keyword on a pointer. After the object is constructed, you can call it's Create member method. The fifth parameter of Create is of type CMDIFrameWnd* . This is the address of the class, which is to be the parent of this newly created window. The framework uses this pointer to determine the associated window object and actually specify it as the parent, but we only need to pass the wrapper class's address.
Now, when you create new child windows, you usually call the Create member method from inside a function belonging to the CMDIFrame class, such as OnCreate or OnCreateClient . As you are calling from inside the class's context, the this pointer points to the calling object. Logically, you pass the this pointer as the fifth parameter to specify the calling object (and indirectly the associated window object) as the parent of the new MDI child window.
If you are not creating the child window from inside the context of the frame window class, then you can use the pMainWnd pointer, residing the in the application object, to refer to the main window of your application. This is usually the frame window. Naturally there are alternative methods, and many of them, such as using the extern keyword. What method you use is up to you.
Hope this will be helpful,
Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Use Constructor to pass the values
x = something * u*;
y= something....;
.
.
.
CNewDialog myDlg(int x, int y,....);
------------------------------------------------
when you create new object this value will be in your constructor and you can access this values!!!
regards
Balkrishna Talele
|
|
|
|
|
hi, below is my on draw...
it works fine as below...
code:
--------------------------------------------------------------------------------
void CEditorView::OnDraw(CDC* dc)
{
CMemDC pDC(dc);
OnPrepareDC(pDC);
CEditorDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here - use pDC
//as the device context to draw to
//
//Set the mapping mode to LOENGLISH
//
pDC->SetMapMode(MM_LOENGLISH);
//
//Convert arguments to coordinates to MM_LOENGLISH units.
//
CSize szTemp;
szTemp.cx = pDoc->GetGridX();
szTemp.cy = pDoc->GetGridY();
pDC->DPtoLP(&szTemp);
//
// then draw the grid lines
//
CRect clipBoxRect;
pDC->GetClipBox(&clipBoxRect);
for(int x = 10 ; x <= pDoc->GetGridX() ; x += 10) {
pDC->MoveTo(x, -10);
pDC->LineTo(x, -pDoc->GetGridY());
}
for(int y = -10 ; y >= -pDoc->GetGridY() ; y -=10) {
pDC->MoveTo(10, y);
pDC->LineTo(pDoc->GetGridX(), y);
}
}--------------------------------------------------------------------------------
it works perfectly fine as below....
now the problem is i wanan add this to my above code
code:
--------------------------------------------------------------------------------
//
//Draw the squares
//
/*for(int i = 0 ; i < 500 ; i ++) {
for(int j = 0 ; j < 750 ; j ++) {
COLORREF color = pDoc->GetSquareColor(i, j);
CBrush brush(color);
int x1 = (j * 10) + 10;
int y1 = (i * -10) - 10;
int x2 = x1 + 10;
int y2 = y1 - 10;
CRect rect(x1, y1, x2, y2);
pDC->FillRect(rect, &brush);
}
}*/--------------------------------------------------------------------------------
when i do this...
all the processing power of the processor is eaten up by the processor....
can someone pls tell me a solution by which i can incorporate the above code to my View's OnDraw such that i can still retain my processing power????
tks a lot...
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
"For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
John 3:16
"Therefore you also be ready, for the Son of Man is coming at an hour you do not expet."
Luke 12:40
|
|
|
|
|
It is not advisable to have a lenghty operation like yours within the UI thread because it gets blocked.
Look up worker threads in MSDN.
Peter Molnar
|
|
|
|
|
help me,
my question is :
i can't get the text in CComboBox that i input when the program is run
(CComboBox m_DBName);
int index=-1;
index=m_DBName.GetCurSel();
//if i input "sdfs",the next cause a error
str=m_DBName.GetCurrentText();
|
|
|
|
|
|
no ,GetLBText() can't,i have try,
my porpuse:
get the user input not the user select
|
|
|
|
|
GetWindowText
Happy Gemini
|
|
|
|