|
This is not really an ATL, WTL or STL question. But, as I'm a nice guy, I'll suggest you open your files in binary mode (fopen(filename, "rb") or fopen(filename, "wb") , so that the C run-time doesn't do any translation of line-ending characters.
Alternatively (and this is better), you can embed the executable file you want to write as a resource in the program that is generating it. Here's a function that should load and write a named resource:
#include <Windows.h>
#include <ShlWApi.h>
bool WriteFileFromResource(HINSTANCE hmodResource, LPCTSTR name, LPCTSTR type, LPCTSTR destination)
{
if (!type)
type = ::PathFindExtension(name) + 1;
HRSRC rsrcFile = ::FindResource(hmodResource, name, type);
if (!rsrcFile) false;
HGLOBAL gblFile = ::LoadResource(hmodResource, rsrcFile);
if (!gblFile) false;
DWORD sizeFile = ::SizeofResource(hmodResource, rsrcFile);
if (!sizeFile) return false;
LPVOID filePointer = ::LockResource(gblFile);
if (filePointer)
{
bool ret = false;
HANDLE hFile = ::CreateFile(destination, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
if (hFile)
{
DWORD nBytesWritten;
ret = (::WriteFile(hFile, filePointer, (DWORD)sizeFile, &nBytesWritten, 0) && sizeFile == nBytesWritten);
::CloseHandle(hFile);
}
::FreeResource(gblFile);
return ret;
}
return false;
}
|
|
|
|
|
I need to develop a COM dll which will read data from a serial port.
I am very new to COM programming.
Please help me regarding this.
|
|
|
|
|
What is the problem ? Where are you stuck ? What did you try so far ?
|
|
|
|
|
I just learnt to create a simple object in ATL.
Now my requirement is to write an object which will open a serial port and read data from it.
I got some code which will make use of CreateFile and read data from it.
But i dont know exactl where can use the code what will be the function return type because i am developing a ATL dll.
So i am unable to procede further.
|
|
|
|
|
hari_honey wrote: I got some code which will make use of CreateFile and read data from it.
But i dont know exactl where can use the code what will be the function return type because i am developing a ATL dll.
So i am unable to procede further.
Hence you need to go deeper inside documentation.
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
|
|
|
|
|
Hi,
We have this piece of code in OnSheetInitialized():
// Add minimize button to the standard property sheet.
this->ModifyStyle(0, WS_MINIMIZEBOX);
This seems to work on XP, but not on Vista (with Aero turned on).
The minimize button shows up correctly, but on clicking it nothing happens on Vista(with Aero).
I set a breakpoint in CPropertySheetImpl::OnSysCommand, and on Vista with Aero turned off, it breaks into this handler on clicking minimize, but doesn’t do so when Aero is enabled.
|
|
|
|
|
i created a dll....that uses the function..
headerfile
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
DLLIMPORT LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
#endif /* _DLL_H_ */
cpp file
/* Replace "dll.h" with the name of your header */
#include "key.h"
#include <windows.h>
DLLIMPORT LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
//some code here.....
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
MessageBox( NULL,"Test working","cool",MB_OK | MB_ICONINFORMATION);
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
when im compiling this dll with Dev-C++ compiler..im getting error....
my compiler log is:
Compiler: Default compiler
Building Makefile: "D:\devcpp project\keylogger\testlogger\sysproc\Makefile.win"
Executing make...
make.exe -f "D:\devcpp project\keylogger\testlogger\sysproc\Makefile.win" all
g++.exe -c dllmain.cpp -o dllmain.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -DBUILDING_DLL=1
In file included from dllmain.cpp:2:
key.h:10: error: `LRESULT' does not name a type
make.exe: *** [dllmain.o] Error 1
Execution terminated
can someone please help me what im doing wrong...what im able to understand is that it is not able to get the declaration for LRESULT......
how to correc that.....
thanx in advance...dudes
|
|
|
|
|
Two remarks first: this is not the correct forum, it is more related to the C++ forum. Also, please format your code properly using the PRE or CODE tags, it will be much easier to read.
Now to your problem, did you include windows.h at the top of your file ?
|
|
|
|
|
Dear friends,
I want to make a Internet Explorer plugin which works like mcafee siteadvisor browser plugin. When user does a google search, it should be able to show the rank as per my specifications on the result list of google search. The ranks are in scale of 0-10 and will be shown as and where mcafee siteadvisor shows the green red coloured buttons.
To me the key challenge area is to grab the google search result list, and then show the scores on the google search result page. Do I need to use dhtml/javascript?
Thanks in advance
Bikram...
|
|
|
|
|
Hi all,
I'm writing a toolbar for IE. I want to open a menu (or a simple window - not a dialog) that will open outside of the toolbar space (but inside IE).
I want to catch the mousemove, and to draw my own graphics which change depending on the mouse location.
I tried using TrackPopupMenu, however I didn't find any way to catch the mouse-move, or to draw the menu on my own.
I'm using WTL.
Thanks a lot,
Amos
|
|
|
|
|
Hi All,
I have developed a ATL COM which has a dependency , i have registered callback function of ATL COM to the dependency , which is ultimately invoked by one of the thread of the dependency and i am firing Event when callback funciton is invoked from callback function in ATL COM ,
Also i have implemented the way it is given the to fire event from Worker thread
including atlcmplimpl.h ..... etc..
The event is fired from the worker thread correctly but ..
My problem is in Internet Explorer , When ATL COM fires event once , the event is shown on internet explorer more than once as if event is fired many times... i.e each event is shown repeatedly and count is increasing every time..
I have tested ATL COM on VB Client it is working fine on the VB but it is giving problem in the internet explorer...
Here is the code snippet...
//EventCallBack is registered as call back function in depedency module
// It is static function of CCallMonitor as it was to be registered as
//callback function
int CCallMonitor::EventCallBack(void* pData)
{
HRESULT hRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
MessageBox(NULL,TEXT("Fire Event Reached"),TEXT("OK"),MB_OK);
//g_CallMonitor is the pointer to the COM CLass
g_CallMonitor->Fire_IncomingCall((BSTR)Objbstr);
::CoUninitialize ();
MessageBox(NULL,TEXT("After Test Reached"),TEXT("OK"),MB_OK);
return S_OK;
}
MessageBox for debugging purpose only...
Please let me what is the problem with the same...
with regards
Abhiraj
|
|
|
|
|
Hi all, I am relatively new to ATL/Com but I have some understanding.
I've stolen code from one project and put it in another project. I then modified it for this project's task. The two are 99% the same, except for the sink object. It is pretty standard code really. First I init the interface:
<br />
HRESULT hr=S_OK;<br />
hr = CoCreateInstance(__uuidof(StorageCOM), NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void **)&pIUnknown);<br />
if (SUCCEEDED(hr))<br />
{<br />
hr = pIUnknown->QueryInterface(__uuidof(IStorageCOM), (void **)&pStorageIF);<br />
if (SUCCEEDED(hr))<br />
{ <br />
<br />
} else <br />
qDebug() << "GridWrapper::GridWrapper pIUnknown->QueryInterface(__uuidof(IStorageCOM)...) failed";<br />
<br />
} else <br />
qDebug() << "GridWrapper::GridWrapper CoCreateInstance(__uuidof(StorageCOM)...) failed ";
Then I try to make the sink and subscribe it to events:
<br />
CComObject<storageeventsink>::CreateInstance(&pSinkObj);<br />
long hr=S_OK;<br />
hr = pSinkObj->QueryInterface(IID_IUnknown, (void**)&pEventSink);<br />
<br />
if (pEventSink && SUCCEEDED(hr))<br />
{<br />
hr = AtlAdvise(pIUnknown, pEventSink, DIID_IChunkEvent, &sinkCookie);<br />
if (SUCCEEDED(hr))<br />
{<br />
qDebug() << "connecting to psinkobj=" << pSinkObj;<br />
if (connect(pSinkObj, SIGNAL(chunkReady(QByteArray)), this, SLOT(onChunkReady(QByteArray))))<br />
{<br />
QSignalSpy spy(pSinkObj, SIGNAL(chunkReady(QByteArray)));<br />
qDebug() << "Spying on psinkobj=" << pSinkObj;<br />
int x = pStorageIF->GetChunkedFile((unsigned char *)UUID.data(), cookie);<br />
qDebug() << "pSinkObj emitted" << spy.signal() << spy.count() << "times";<br />
} else qDebug() << "connect of sink to this failed";<br />
AtlUnadvise(pIUnknown, DIID_IChunkEvent, sinkCookie);<br />
} else qDebug() << "AtlAdvise failed";<br />
} else <br />
qDebug() << "GridWrapper::GridWrapper pSinkObj->QueryInterface(IID_IUnknown, pEventSink) failed";<br />
<br />
pEventSink->Release();<br />
<br />
</storageeventsink>
The problem I am running into is in STDMETHODIMP IConnectionPointImpl<t, piid,="" cdv="">::Advise(IUnknown* pUnkSink,DWORD* pdwCookie)</t,> (of atlcom.h)
Where it says :
<br />
*pdwCookie = m_vec.Add(p);
For m_vec, m_ppUnk==NULL and m_nSize=0
This add() actually fails, and I have no idea why.
I am hoping someone has a better idea than myself of what might be going wrong. Thanks!
EDIT: It seems that
inline DWORD CComDynamicUnkArray::Add(IUnknown* pUnk)<br />
<br />
ATLTRY(pp = (IUnknown**)calloc(sizeof(IUnknown*),_DEFAULT_VECTORLENGTH));<br />
is failing
modified on Thursday, May 1, 2008 2:42 PM
|
|
|
|
|
I did a window just for the menu so inherit from CFrameWindowImpl.
Then I add dynamic items to the menu.
I captured the MSG_WM_MENUCOMMAND(OnMenuCommand)
In the function "OnMenuCommand" I try to get the information of the item ...
The menu handle was invalid...
So I did a test and found out so
The message "MSG_WM_UNINITMENUPOPUP" is sent before the message "MSG_WM_MENUCOMMAND"
Why is it so? and how I can solve the problem?
Thanks in advence
|
|
|
|
|
Hi!
I'm Rathakrishnan. I'm new to ATL. I've to develop a customized tool bar project for web. I've a sample code. When I debug the code, it gives me the following two kind of errors:
(i)error C2787: 'IInputObject' : no GUID has been associated with this object
(ii)error C2440: 'initializing' : cannot convert from 'DWORD_PTR' to 'const IID *'
The error prone code is:
BEGIN_COM_MAP(CStockBar)
COM_INTERFACE_ENTRY(IStockBar)
COM_INTERFACE_ENTRY(IInputObject)
COM_INTERFACE_ENTRY(IOleWindow)
COM_INTERFACE_ENTRY_IID(IID_IDockingWindow, IDockingWindow)
COM_INTERFACE_ENTRY(IObjectWithSite)
COM_INTERFACE_ENTRY_IID(IID_IDeskBand, IDeskBand)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
What might be the problem? How do I resolve this?
|
|
|
|
|
Microsoft's compiler allows you to associate an interface with its IID. This means that for such an interface, the compiler can give you a reference to the IID.
To associate an interface with an IID, you use the __declspec(uuid()) directive. Example:
struct __declspec(uuid("D97A6DA0-A85D-11CF-83AE-00A0C90C2BD8")) IMyInterface { ... }; This tells the compiler to create an IID in static memory with the specified value. A pointer to the IID is then acquired by using the __uuidof() operator like this:
const IID* pIID = __uuidof(IMyInterface)
If you use Microsoft's IDL compiler (MIDL), the association between interface and IID is made automatically for you. Also, most of the system interfaces (IUnknown , IDispatch , etc.) also have this feature.
It would seem to me that there is no IID associated with IInputObject. There is most likely an IID variable declared somewhere that you can use. Have you tried swapping COM_INTERFACE_ENTRY(IInputObject) with COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject) ?
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
Hello dear friends,
How can we Use ATL COM dll in JavaScript?
Suppose I've one function in CoClass of COM DLL that looks like as below
STDMETHODIMP CQpOffice::SayHello(BSTR *String,BOOL *Success)
How can I call this function from the Javascript.
A sample code will be appreciated.
Thanks in advance to all of you.
ritz1234
|
|
|
|
|
|
You've also to make sure your COM class implements the IDispatch interface.
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
|
|
|
|
|
Thanks for the reply,
The problem is when I run the JScript in Mozilla Firefox browser it says
that ActiveX object is not defined.
My CoClass is defined as shown below.
class ATL_NO_VTABLE CQpOffice :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CQpOffice, &CLSID_QpOffice>,
public IDeskBand,
public IObjectWithSite,
public IDispatchImpl<IQpOffice, &IID_IQpOffice, &LIBID_AUTOUPDATETBLib>
and the interface method is defined as
STDMETHODIMP CQpOffice::Hello2(BSTR *String)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
if(!String)
return(E_POINTER);
*String=::SysAllocString(L"Hello2!");
return S_OK;
}
and the JScript to call the interface method is defined as
var obj;
obj= new ActiveXObject("AUTOUPDATETBLib.QpOffice");
alert(obj.Hello2());
What could be the problem so I received the error "ActiveX object not defined" the COM DLL is registered in the system and I can see the CoClass and Interface method in "Object Browser" in Visual Basic 6.0.
ritz1234
|
|
|
|
|
ritz1234 wrote: ("AUTOUPDATETBLib.QpOffice"
Is that the right progID (you may use OLEVIEW to check it)?
Are you able to late bind the control using Visual Basic 6 ?
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
|
|
|
|
|
Thanks for the reply cPallini.
yes,that was the wrong progId.
I realized that and changed the code in JScript as below
var ob;
ob= new ActiveXObject("AutoUpdateTB.QpOffice");
alert(ob.Hello2());//Hello2 is the interface method that returns a string
When I drag and drop the html page that has the above mention code the
Internet explorer ask for weather to allow the interaction with the
ActiveX or not, that means the progId is right in this case.But when I
press "Yes" button the messagebox that should be display doesn't appear.
And when I double click at the left most icon located at the bottom
status bar it says "Automation server can't create object".
Pls tell me what is the reason.
1 more question.
1)Is it possible to call the COM DLL method in such a way, that when we call the method the messagebox that Internet Explorer ask for weather to allow the activex to interact doesn't appear?
ritz1234
|
|
|
|
|
I'm implementing a dialog that inherits off CSimpleDialog that's part of a CAtlDllModuleT. The dialog loads fine, but one of the things I'm trying to do is to move the resource of the dialog into a different DLL, to make it easier to internationalize (replace the dialog text, etc).
I know how to load the resource DLL, but I'm unsure of how to tell my dialog class to specifically load the dialog resource from that DLL.
Thanks in advance for any suggestions. If I'm not clear in anything, do ask me to clarify.
|
|
|
|
|
|
How to handle COM Events in Java script
How to use ATL COM in java script and handle COM event in java script
if the ATL COM is developed in C++
Abhiraj
modified on Tuesday, April 29, 2008 2:43 AM
|
|
|
|
|
|