|
Hi,
I have a program that uses a COM object. At somepoint I try to release the object. After I do the release process, I can see using Process Explorer that the ActiveX DLL is still in memory.
My code is below. Am I doing something wrong? Why is the DLL still in memory?
ComReleaseTest.DLL is a test VB ActiveX DLL I wrote to debug this problem. It does nothing - all it has is one test sub which I am not even calling.
<br />
#include "stdafx.h"<br />
<br />
#import "..\ProductTree\winpos\drv32\ComReleaseTest.dll" no_namespace<br />
<br />
_CComReleaseTestPtr m_Srv;<br />
<br />
int Close();<br />
void ReleaseObject();<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
HRESULT hResult;<br />
<br />
try<br />
{ <br />
if ( TRUE )<br />
{<br />
hResult = CoInitialize( NULL );<br />
<br />
if ( hResult != S_OK )<br />
{<br />
return 1;<br />
}<br />
}<br />
<br />
HRESULT hr = m_Srv.CreateInstance(__uuidof( CComReleaseTest ), NULL, CLSCTX_ALL);<br />
if (FAILED(hr))<br />
_com_issue_error(hr);<br />
}<br />
catch(_com_error& e)<br />
{<br />
return (1);<br />
}<br />
<br />
Close();<br />
<br />
return (0);<br />
<br />
}<br />
<br />
int Close()<br />
{<br />
long Result = 0;<br />
<br />
if ( m_Srv != NULL )<br />
{<br />
TRY<br />
{<br />
ReleaseObject();<br />
}<br />
CATCH_ALL(e)<br />
{<br />
TCHAR sError[255];<br />
e->GetErrorMessage(sError,255);<br />
}<br />
END_CATCH_ALL<br />
}<br />
<br />
return ( (short)Result );<br />
}<br />
<br />
<br />
<br />
void ReleaseObject()<br />
{<br />
<br />
try<br />
{<br />
m_Srv.Release();<br />
}<br />
catch(_com_error& e)<br />
{<br />
}<br />
<br />
free(m_Srv);<br />
m_Srv.Detach();<br />
<br />
<br />
m_Srv = NULL;<br />
<br />
}<br />
<br />
<br />
The reason I am trying to track this is that I have anotehr program that at somepoint calls an InstallShield 5.5 setup. This setup.exe hangs at 99% and I found that if my program does not call a certain ActiveX then there is no problem with the setup.exe. So I am trying to release that ActiveX before calling setup.exe, but the COM DLL just stays in memory!
|
|
|
|
|
|
Thank you very much. You are a genius! Problem solved.
|
|
|
|
|
Hi Friends,
I need to add a new item into the context menu we see while we right click on a control panel item and show a message box when user clicks on my item.I just want to display the name of the item on which the user right - clicked in the message box.
Any ideas?
Thanks and regards,
J
|
|
|
|
|
All control panel items are actually DLL files that end with a .CPL extension.
To add a menu item to its context menu, you need to create a shell extension.
Look at this tutorial here - The Complete Idiot's Guide to Writing Shell Extensions - Part I[^]
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hi,
I am making my application unicode supporting one. i face a problem like this now :
i have got some content in *.inf file..
i am unable to read the content of the file using Readfile(..) function.
code snippet:
-----start-------------
TCHAR * inifilecontents;
HANDLE hFile = CreateFile( iniFilePath,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD nfile_Size = GetFileSize(hFile, NULL);
if (nfile_size != INVALID_FILE_SIZE)
{
m_nBufferSize = nFileSize + 1;
iniFileContents = new TCHAR[m_nBufferSize];
ZeroMemory(m_pIniFileContents, m_nBufferSize);
DWORD bytestoread = nFileSize;
DWORD bytesread = 0;
-----> BOOL bReadSucceeded = ReadFile(hFile,inifileContents,bytestoread,bytesread,NULL);
----------End---------------------
after executing readfile funcion, inifilecontents are showing contents as "some small BOXES" and not the exact content of inf file....
please guide me on this...
Thanks,
Rakesh
|
|
|
|
|
May be because your inf file isn't in unicode format. If so you have to read the content as char* itself and then convert it to unicode string using MultiByteToWideChar() function.
|
|
|
|
|
Are you sure that you're compiling for Unicode?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Actually i dont have unicode content in the file as of now. but still its not showing even the ASCII content of the file..
when i tried CPallini' suggestion, it showed message box with boxes...
( that was the same thing as i tried earlier..)
Can u enlighten me what can i do for this?
Thanks,
Rakesh
|
|
|
|
|
Well, what do you mean it's not "showing". Where are you trying to show it? An edit control? The debugger watch window? How exactly are you verifying the value of the buffer read?
BTW, this is pointless: m_nBufferSize = nFileSize + 1; Instead of 1 , you must choose sizeof(TCHAR) if you want really neutral code.
[Added] Why are you reading a .inf file with ReadFile() ?!
Shouldn't be using the GetPrivateProfileString()[^] and other similar functions designed for this purpose?
It is a crappy thing, but it's life -^ Carlo Pallini
modified on Wednesday, July 15, 2009 5:58 AM
|
|
|
|
|
Rakesh5 wrote: after executing readfile funcion, inifilecontents are showing contents as "some small BOXES" and not the exact content of inf file....
Actually that's the exact file content. Try to show it with, for instance
MessageBoxW(NULL, (LPCWSTR) inifilecontents, L"TEST", MB_OK);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
In short, using the ReadFile, will read the file content as bytes. Neither as unicode nor as MBCS, but simply as binary data. It is our concern whether it should be treated as unicode or not.
I am ignoring the inconsistency of the variables in your sample code. But still I found a mistake in your code.
That is you are allocating the buffer as 'new TCHAR[m_nBufferSize]'. It is wrong since the GetFileSize will return the exact size of the file in number of bytes. So when you are compiling with unicode enabled, the size of the TCHAR will be 2 (means sizeof unsigned short) and the buffer allocated will be twice of what we needed. Also it should be noted that the data read will not be directly converted to unicode (even if the buffer is of TCHAR).
And, from your question I understand that your file will be in unicode format. If this is true, then you can read it as follows. (modifications might be necessary)
int nSize = GetFileSize(...);
byte* pBytes = new byte[nSize];
ReadFile(..., pBytes, ...);
MessageBox(.., LPCTSTR(pBytes), ... );
This is the case when your file is in binary format.
When you save a file as unicode using notepad, you can see the first two bytes will be FF FE. So when you reading the file you can check that for ensuring the file is unicode and can ignore those bytes from using as data.
Suppose the content of a unicode file is 'abcd', then the binary equalent will be FF FE 61 00 62 00 63 00 64 00. You can see this when you open a file as binary in the VC editor itself.
I hope my explanation is clear for you.
(By the way, I am not sure about any APIs which will directly read a unicode file)
- ns ami -
|
|
|
|
|
what is IWshRuntimeLibrary? when can it be used.
|
|
|
|
|
May I politely google that for you [^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I have created an SDI application andi want to add two buttons to it for zoom in and zoom out.how can i do that?
|
|
|
|
|
You want the buttons to be added to the toolbar. Right?
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Open the toolbar in the toolbar editor (double-click on the toolbar in the Resource View) and click on the blank button on the right side of the toolbar to create a new button. Type a suitable ID into the toolbar button's Properties view (something like ID_VIEW_ZOOMIN?). Now draw something on that to represent 'zoom-in' (a magnifying glass with a + usually works). Now repeat (but changing the details as appropriate) for the zoom-out button.
Now you can handle the zoom-in and zoom-out events, probably in your View class.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
How to read command line args in vc++.
Is there any predefined function/class available?
|
|
|
|
|
What type of application are you working on?
If it's a simple console based application you can read the information in the main function (usually named as argc and argv).
Also you can see here:Reading Command line arguments[^]
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
...and if you're using MFC, see m_lpCmdLine , which is a member of CWinApp .
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Command line arguments are available in the main function of your program (that is WinMain for a GUI application). If you're using MFC , your-CWinApp -derived class provides the m_lpCmdLine [^] member.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks for the information.
|
|
|
|
|
|
the code below create a folder in drive E:\ called autorun.inf and other line to create inside autorun.inf folder a text file called protection.txt
now what i want is instead of creating these things in drive E:\ i want the user to enter the drive letter that he wants then these files will be created in the entered drive
#include <direct.h>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
_mkdir("e:/autorun.inf");
ofstream output("e:\\autorun.inf\\protection.txt",ios::out);
output.close();
return 0;
}
Thanks in advance
|
|
|
|