thanks, the article was really helpful. i used BSTR
to pass the array safely among processes. i thought i needed some structure like BSTR
for this, but couldn't imagine the solution would be BSTR
itself :) WM_COPYDATA
is useful too, but since my UserBroker does not have a window, i can't send the message to anywhere else. thanks again
ajitatif angajetor
Posts
-
pointer problem :) -
pointer problem :)hi everyone, i'm working on a project which includes a DLL and a separate UserBroker (both written in ATL) object which is used for getting/setting registry keys and reading/writing to user directories. (the object will be used in Vista, so this is needed) i want to read some binary data from registry and i have written this function properly:
STDMETHODIMP CUserBroker::QueryBinaryValue(BSTR bstrKeyName, BSTR bstrValueName, BYTE **pValue, ULONG *pnBytes)
the function body is simple. it just opens the registry key (using aCRegKey
) and uses itsQueryBinaryValue
method. the problem is somehow i just can't pass aBYTE
array to the other process (which calls theCUserBroker
's method). the call to the method is this:arr = (BYTE *)malloc(1 * sizeof(BYTE)); pub->QueryBinaryValue(ATL::CComBSTR(s_bstrToolBarRegistryKey), ATL::CComBSTR("hop"), &arr, &dwSize); arr = (BYTE *)realloc(&arr[0], (dwSize) * sizeof(BYTE)); pub->QueryBinaryValue(ATL::CComBSTR(s_bstrToolBarRegistryKey), ATL::CComBSTR("hop"), &arr, &dwSize); delete arr;
everything works fine until the first line ofCUserBroker::QueryBinaryValue
method, where theBYTE**
pointer points toBadPtr (0x00000000)
immediately. the question: how can i pass aBYTE
array (or any other array) among processes? -
how to get the VARIANT type URL as a CString from OnDocumentComplete in webbrowser2you can use the
V_BSTR
macro to get it done. the macro returns aBSTR
that you can use to obtain aCString
. something like this may help/work:BSTR bstrUrl = V_BSTR(URL); CString cstrUrl(bstrUrl);
-
Multiple Inheritance by IDispatch:-D uuuuuuh,no. I added an
IDispEventImpl
to inheritance list and it worked.Great help,thanks:) -
Multiple Inheritance by IDispatchHi everyone, I have a class that implements an interface that derives from IDispatch directly,and I want to add a new interface which also derives from IDispatch,and then derive my class from this interface too.Expectedly,my problem is ambiguouty (did I spell it correctly??).I use
COM_INTERFACE_ENTRY2
macro,but i keep getting error "cannot instantiate abstract class" error in atlcom.h this is the IDL file:library TheLibrary { importlib("stdole2.tlb"); [ object, uuid(), dual, nonextensible, helpstring("Primary dispatch interface for the class."), pointer_default(unique) ] interface ISomething : IDispatch { }; [ uuid(), helpstring("help string.") ] coclass CSomething { [default] interface ISomething}; [ uuid(), nonextensible, helpstring("the new Interface"), ] dispinterface INewInterface { properties: methods: [id(0), helpstring("method default"), local] HRESULT DefaultMethod(void); };
and this is the COM mapping
BEGIN_COM_MAP(CSomething) COM_INTERFACE_ENTRY(ISomething) COM_INTERFACE_ENTRY2(IDispatch, ISomething) COM_INTERFACE_ENTRY(IObjectWithSite) COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IDeskBand) COM_INTERFACE_ENTRY_IID(IID_IDockingWindow, IDeskBand) COM_INTERFACE_ENTRY(IDeskBand) COM_INTERFACE_ENTRY_IID(IID_IInputObject,IInputObject) COM_INTERFACE_ENTRY(IPropertyNotifySink) COM_INTERFACE_ENTRY(INewInterface) END_COM_MAP()
I tried using
interface
instead ofdispinterface
.Didn't help either.I know I'm missing something,but can't figure out what it is... -
Adding a new image (img tag) to the document in Internet ExplorerHi everone, I'm developing an Internet Explorer add-on,which will put an extra image on the document's specified location.Everything works fine,but Internet Explorer won't display the image if it is located in the local system (the user's computer,i mean).Since I'm sure the image url (formed as '
file://c:/folder/image.gif
') is correct and IE displays images on the internet,I think it's a kind of security feature of IE. Does anyone have any idea on how I can put a local image on the document without asking the user to alter security settings?:~ -
Hi All !(CString Class)you can try the
_ttoi
function to determine if the string is actually an integer. The function will return0
if the string cannot be parsed as integer. So you should also check if user actually entered0
in theCEditBox
. "What if user enters something like0000
?" question still remains, but this is better than nothing :)int val = _ttoi(sCod); if (val == 0 && sCod != _T("0")) { AfxMessageBox(_T("Incorrect number")); }
-
int array problemAlternatively, you can use
int
pointers instead of array. This way you can check if the value isNULL
-
Catching Key Event of an Edit BoxI checked out the article but there's something I just can't catch: The
ComboBoxEx
does not recieve anyWM_KEYDOWN
events from theEditBox
within. I used Spy++ to see that the event doesn't even get past theComboBox
control inside the ComboBoxEx. So, how can I catch theWM_KEYDOWN
event when I can't catch it on the parent? -
About Tetris gameboth questions have one answer: i guess you re-draw tetris blocks each time they move, using rectangles (
RECT
structure) of the block parts. so what you have to do is to check if left-most,right-most and bottom-most rectangles are inside the main window rectangle. also, the block should stop moving when the bottom-most rectangle of it touches the top-most block's rectangle on the same game column (each block part is one column wide). you can get the rectangle of the main window usingGetWindowRect()
function. but don't forget to use,ClientToScreen()
andClientToParent()
functions when needed, they save more than just time. -
pointers and structuresi couldn't catch what you exactly want, but can a constructor help you? you could create a constructor that takes these values as argument and get the values one by one from console. then, create a new books struct with the values.
-
Catching Key Event of an Edit BoxHi everyone, I've been digging up for a way to handle key presses (specifically CTRL+A KeyDown) for the EditBox in the ComboBoxEx in my IE toolbar and have failed everytime. I tried to handle the
WM_KEYDOWN
events but I just couldn't. The ComboBox won't fire any event and I want to select all the text within the EditBox when user presses CTRL+A. There must surely be a way but what could that be? -
Menu using ATLfirst, create a menu in your resource file. second, put a button to the toolbar that will open the menu up with a style BTNS_WHOLEDROPDOWN third, get a command handler handle the button's command (
WM_COMMAND
message ) and lastly, write a method that creates the menu and tracks it. something like:HMENU hM = ::LoadMenu(ATL::_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(ID_MENU); HMENU hMPopUp = ::GetSubMenu(hM,0); // calculate the point where the menu will show ::TrackPopupMenu(hMPopUp,TPM_TOPALIGN,pointX,pointY,0,m_hWnd,NULL);
that's the way i did it, i think you can handle the rest with the holy MSDN
-
"Access Violation Error" Using Custom COM [modified]nice touch, but the moment you ask for
HKEY_CURRENT_USER
in a low integrity process, windows vista will give you theHKEY_CURRENT_USER\Software\LowRegistry
key. so the low integrity process will read/write to a position likeHKEY_CURRENT_USER\Software\LowRegistry\<user_id>\Software\LowRegistry
-
"Access Violation Error" Using Custom COM [modified] -
"Access Violation Error" Using Custom COM [modified]i'm trying to create a broker process for an internet explorer toolbar to work on windows vista. internet explorer (only in vista) puts the toolbar on low registry profile on most of the web pages (all except those in trusted zone), which gets things complicated. you open a trusted site and toolbar tries to read from HKCU, you open another site and it tries to read from HKLM\Software\Microsoft\InternetExplorer\LowRegistry... something. so what i'm doing is to use an executable file (which will always work on low profile) to do the trick. toolbar just says "save the setting", and turn away. executable will always save these settings to the LowRegistry key. this is what i understood on msdn articles, did i simply misunderstood them?
-
"Access Violation Error" Using Custom COM [modified]i created another project whose proxy-stub is merged and now the problem is resolved into another one: i use HKEY in some of the functions as in and out parameters (they use registry keys), and my IDL file thinks HKEY is void *, contrary to the caller class, which sees HKEY as struct HKEY__* (as it should). i think this causing inconsistency between the client and the server, since i get "bad variable type" (or something similar) from CoCreateInstance only when there is a method with a parameter typed HKEY in the server. i tried redeclaring HKEY in IDL file,including winnt.h but no luck. any hope here?
-
"Access Violation Error" Using Custom COM [modified]hi everyone, i created a custom COM component (.exe) which is used by another .dll. i compiled the both components fine, including the code snippet below; but i get a runtime access violation error on line of exe->Dummy() after CoCreateInstance returns S_OK. it gives different addresses for each different method of the .exe component i try. this code is inside a method of the .dll component
HRESULT hr = 0; ATLVERIFY(SUCCEEDED(CoInitialize(NULL))); ATL::CComPtr exe; hr = exe.CoCreateInstance(CLSID_Something,NULL,CLSCTX_LOCAL_SERVER); // call out for .exe component ATLASSERT(SUCCEEDED(hr) && exe != NULL); ATLVERIFY(SUCCEEDED(exe->Dummy())); // access violation here exe.Release(); // doesn't make it to here anyway
My .exe component is non-attributed just like the .dll (not sure if it makes any difference), i have built and registered the proxy-stub class fine, and also my .exe file is registered with "exe /RegServer". i think there is one more thing to be done but just couldn't find out what. if it were the registry script or something, i shouldn't be getting an instance of the .exe component. any ideas ? please have some !! -- modified at 14:18 Thursday 22nd March, 2007 edit: i converted the .exe interface to be non-dual (it was a dual interface before) and this time exe->Dummy() returns "A null reference pointer was passed to the stub." -
Convert LPWSTR to LPSTRHi everyone, I need to convert a unicode
LPWSTR
to multi-byteLPSTR
.wcstombs
_s doesn't do good,because it replaces non-english characters to their english likes (like ş->s and ı>i).WideCharToMultiByte
function seems to do this right,but the double-byte characters in the convertedLPSTR
are interpreted as if they are two single-byte characters. to be more specific,I use MAPI dll to send an e-mail.MAPI dll expects all strings to beLPSTR
which maps toint
.but i want to use non-english characters in e-mail's body/subject/attached files' names,and couldn't find a solution yet.it's all good when strings are in english,because all unicode characters map to asigned char
then.but when i get a non-english character,"problem".LPSTR
seems to interpret all characters to be single-byte. any suggestions? -
Displaying a ToolTipuh,i had to hack my code much more throughly to see it was all about rectangles.i found out that the toolbar had one of the items resized after i created the tooltip (with the wrong rectangles). and i added a
TB_SETTOOLTIPS
message right after theTTM_ADDTOOL
.works just fine now,thanks for everything :)