|
Hi ...
I have written a Windows Service using ATL COM (ATL3 / Visual Studio 6.0). The service works fine, I am able to start and stop the service.
I have created a COM Class called CTest with a methof called TestBeep(). I would like to access this object and call the method from the CServiceModule::Run() method.
Below is the CServiceModule::Run() Method.
The code will fail on both attempts to create the ITest* pTest using CoCreateInstance(). The error message are written to the event log
"Error: ITest failed"
"CoCreateInstance failed"
Any help is appreciated,
Thanks,
Chris
void CServiceModule::Run()<br />
{<br />
_Module.dwThreadID = GetCurrentThreadId();<br />
<br />
HRESULT hr = CoInitialize(NULL);<br />
<br />
_ASSERTE(SUCCEEDED(hr));<br />
<br />
CSecurityDescriptor sd;<br />
sd.InitializeFromThreadToken();<br />
hr = CoInitializeSecurity(sd, -1, NULL, NULL,<br />
RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);<br />
_ASSERTE(SUCCEEDED(hr));<br />
<br />
hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, REGCLS_MULTIPLEUSE);<br />
_ASSERTE(SUCCEEDED(hr));<br />
<br />
LogEvent(_T("Blue Service started"));<br />
LogEvent(_T("Message 1"));<br />
LogEvent(_T("Message 2"));<br />
<br />
if (m_bService)<br />
SetServiceStatus(SERVICE_RUNNING);<br />
<br />
MSG msg;<br />
while (GetMessage(&msg, 0, 0, 0))<br />
DispatchMessage(&msg);<br />
<br />
_Module.RevokeClassObjects();<br />
<br />
<br />
<br />
char progID[] = "Blue.Test.1";<br />
<br />
CLSID clsid;<br />
wchar_t wide[80]; <br />
mbstowcs(wide, progID, 80);<br />
CLSIDFromProgID(wide, &clsid);<br />
<br />
LogEvent(_T("Attempt to use ITest"));<br />
<br />
ITest* pTest = NULL;<br />
if(SUCCEEDED(CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_ITest, (void**)&pTest)))<br />
{<br />
pTest->TestBeep(); <br />
}<br />
else<br />
{ <br />
LogEvent(_T("Error: ITest failed"));<br />
} <br />
<br />
<br />
<br />
CComPtr<ITest> pObj;<br />
hr = pObj.CoCreateInstance(OLESTR("Blue.Test.1"));<br />
if( SUCCEEDED(hr) )<br />
{<br />
hr = pObj->TestBeep();<br />
if( SUCCEEDED(hr) )<br />
{ <br />
LogEvent(_T("Call to ITest was successful"));<br />
}<br />
else<br />
{ <br />
LogEvent(_T("Error: ITest failed"));<br />
} <br />
}<br />
<br />
if( FAILED(hr) )<br />
{ <br />
LogEvent(_T("CoCreateInstance failed"));<br />
}<br />
<br />
CoUninitialize();<br />
}<br />
<br />
This is the implementation of the CTest Class and the TestBeep() method
<br />
#ifndef __TEST_H_<br />
#define __TEST_H_<br />
<br />
#include "resource.h"
<br />
class ATL_NO_VTABLE CTest : <br />
public CComObjectRootEx<CComSingleThreadModel>,<br />
public CComCoClass<CTest, &CLSID_Test>,<br />
public IDispatchImpl<ITest, &IID_ITest, &LIBID_BLUELib><br />
{<br />
public:<br />
CTest()<br />
{<br />
}<br />
<br />
DECLARE_REGISTRY_RESOURCEID(IDR_TEST)<br />
<br />
DECLARE_PROTECT_FINAL_CONSTRUCT()<br />
<br />
BEGIN_COM_MAP(CTest)<br />
COM_INTERFACE_ENTRY(ITest)<br />
COM_INTERFACE_ENTRY(IDispatch)<br />
END_COM_MAP()<br />
<br />
public:<br />
STDMETHOD(TestBeep)();<br />
STDMETHOD(GetCount)();<br />
int nCount;<br />
};<br />
<br />
#endif //__TEST_H_<br />
<br />
<br />
<br />
#include "stdafx.h"<br />
#include "Blue.h"<br />
#include "Test.h"<br />
<br />
<br />
<br />
STDMETHODIMP CTest::GetCount()<br />
{<br />
<br />
return S_OK;<br />
}<br />
<br />
STDMETHODIMP CTest::TestBeep()<br />
{<br />
Beep(4000, 200); <br />
Beep(1000, 50); <br />
Beep(4000, 200); <br />
Beep(1000, 50); <br />
return S_OK;<br />
}<br />
<br />
Thanks,
Chris
|
|
|
|
|
I want to take a bunch of unit test files from an LGPL opensource project, include them in my _closed_ project, modify them a bit and use it to test parts of my application. Can I do this?
thanks!
|
|
|
|
|
Chintoo723 wrote: Can I do this?
no[^].
You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
d)...
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Chris Losinger wrote: copy and distribute such modifications or work under the terms of Section 1 above,
What does distribute here mean? who wants my work? where should I publish it to call it distributed?
Chris Losinger wrote: a) The modified work must itself be a software library.
As I said, it is only test modules which will be in a seperate .dsp project anways. Does this constitute a library in LGPL terms?
Chris Losinger wrote: You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
Same query as the first one. How should I go about it to make sure I am hiding anything from any third parties that want to use it.
thanks!
|
|
|
|
|
Chintoo723 wrote: What does distribute here mean?
the same thing it means anywhere else: if you give it, sell it or let anyone else use it, you're distributing it.
Chintoo723 wrote: How should I go about it to make sure I am hiding anything from any third parties that want to use it.
please, don't take this as legal advice... i'm not a lawyer
but, i think if anything you distribute (ie. let anyone else use outside your organization use) uses L/GPL code, you need to distribute all the code in that app/library. you can't break it up and put parts of it into closed-source apps or libraries.
the LGPL, as i understand it, lets you link LGPL libs into closed-source apps. but it doesn't let you use the code from those libs in closed-source apps.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
If used only for testing, I believe you can. The key is that you won't be shipping any binaries from code covered by the LGPL.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
|
I have been looking for an answer on this one, but found only references to structures. Basically I have a VB.NET structure containing an member array of onother structure that has to be passed to unmanaged C++. I have been able to pass the structure which has members of type structure, but as soon as I define a member array of that structure I get an error: "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: The operation completed successfully."
This is how I am doing it:
VB.NET:
Public Structure SndStr2
<marshalas(unmanagedtype.i4)> Public memb1 As Integer
<marshalas(unmanagedtype.lpstr)> Public memb2 As String
<marshalas(unmanagedtype.i4)> Public memb3 As Integer
<marshalas(unmanagedtype.i4)> Public memb4 As Integer
End Structure
Public Structure SndStr1
<marshalas(unmanagedtype.i4)> Public memb1 As Integer
<marshalas(unmanagedtype.lpstr)> Public memb2 As String
<marshalas(unmanagedtype.i4)> Public memb3 As Integer
<marshalas(unmanagedtype.r8)> Public memb4 As Double
Public memb5() As SndStr2
End Structure
Declaration: Private Declare Function RcvFun Lib "...\RcvFun.dll" _
(ByRef SndVar As SndStr1) As String
Unmanaged C++:
struct RcvStr1 {
int memb1;
LPSTR memb2;
int memb3;
int memb4;
};
struct RcvStr2{
int memb1;
LPSTR memb2;
int memb3;
double memb4;
RcvStr1 *memb5;
};
LPSTR __declspec (dllexport) __stdcall RcvFun(RcvStr2 **RcvPtr)
{
RcvStr1 RcvVar1;
RcvVar1 = RcvPtr[0]->memb5[0];
return RcvVar1.memb2;
}
If there is anybody out there that did this before, please help!
-- modified at 12:05 Wednesday 22nd February, 2006
|
|
|
|
|
I have created a Listview box which would display data in the Report mode. When filling in the header columns is it possible to set the width to correctly display the full text string?
Most of the examples I have found on the net either give the width a static value or a percentage of the total. I would prefer it if I could simply find the length in dialog units or pixels of the max string to be displayed and set the width according to that.
So far I have found no function which is able to find the length of a string in this manner? Is there a method to doing this or would it be easier to do something like (chars_in_string * static_size)?
|
|
|
|
|
It's been a while since I did this, so if I don't get it exactly right, I apologize.
There is a member function of CListCtrl::GetStringWidth(), though I seem to recall it doesn't quite work as stated in the documentation. I seem to recall having to pad it slightly, but I may be mistaken.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Following on from Joes comment above. Using the LVM_SETCOLUMNWIDTH[^] message, pass LVSCW_AUTOSIZE as the column width and the ListView will automaticaly resize the column to fit the longest string.
Gavin Taylor
w: http://www.gavspace.com
|
|
|
|
|
funny we are working on the same thing at the same time.
i found a function calculating the width of a string
on MSDN. the column here contains numbers only so my code is
HDC hdc = GetDC( _hView );
SIZE size;
BOOL res = GetTextExtentPoint32( hdc, TEXT( "0" ), 1, &size );
ReleaseDC( _hView, hdc );
const int iWidth = res ? ( size.cx * _iDigits ) : 120;
this function can be still helpfull when you want
to size for the largest string of all, not just the visible
ones (which LVSCW_AUTOSIZE does).
also i found out you can size the last column
to take as much space as possible without adding the
horizontal scrollbar (unlike LVSCW_AUTOSIZE_USEHEADER ):
RECT r;
GetClientRect( _hView, &r );
const int iWidth = ListView_GetColumnWidth( _hView, 0 );
ListView_SetColumnWidth( _hView, 1, r.right - r.left - iWidth );
best regards, sebastian
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
Thanks for the info. You say that LVSCW_AUTOSIZE only allows for the width of the visible items, I'm not sure I understand cleary.
1. The header items only?
2. Those which are in view due to scroll limits?
I will play around with it when I get home, thanks again.
|
|
|
|
|
i'm not sure if it got you right but i guess
number 2 is what i meant
i'll try again with more details:
my column contains numbers from 1 to 4000.
when the current view is at the very top you can
only see numbers with one or tow digits.
applying LVSCW_AUTOSIZE now sets the
size to two digits not four since the big number
are out of view and ignored.
maybe i should mention my column header
has "#" as title so it is even shorter than
the numbers. i'm not sure what happens if the
header text is longer than all the row text.
i'm using the control in virtual/getdispinfo mode
maybe that's also playing in here!?
btw i had trouble with two-digit numbers shown
as "1..." so the current text width code is
const int iWidth = res ? ( int )( size.cx * ( _iDigits + 0.25f ) ) : 120;
i hope i put it clearly. i'm not a native speaker.
best regards, sebastian
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
Thanks Sebastian, you have answered my questions clearly and with precission, very much appreciated
|
|
|
|
|
Hi,
I am after a quick fix.
I have dynamically created a CComboBox control.
It works fine, but the drop down part does not seem to draw.
I cannot see any obvious calls to adjust the height of the dropdown
Cheers
|
|
|
|
|
A quick guess - you actually create a combobox with its full dropped down height on
creation. It will self correct the height to one row of text, but remember the original
height.
Iain.
|
|
|
|
|
Cheers Iain just the trick!!
|
|
|
|
|
i have a sdi application and i want to draw a dynamic array that is present in CMainframe. problem is that the onDraw function is present in the view class.
i have tried getting the active view in the cmainframe but if i work with it, application throws exception or something.
please help me, as to how i can draw the variables(contents of the dynamic array) present in the mainframe, on screen.
thankyou
|
|
|
|
|
Why don't you want to draw it on your view ? The view is there for that reason, the mainframe is just the 'window' that will contain your view.
I think you need to review a little bit your program architecture. First, in a SDI application, all data should be contained in your document, not in your mainframe. Then, when the view is painted, it ask for data to the document and it draws this data. Normally, that is the standard way to proceed.
|
|
|
|
|
ok, I kinda know the answer, but maybe I overlooked something.
I have a C linked list collection ( old legacy C code that I don't want to change ).
The new items are added at the beginning of the list.
If I want to pass this pointer around to different classes :
class MainClass
{
MyList* pList;
};
class MyOtherClass
{
MyList* pList;
};
....
MainClass mainClass;
...
MyOtherClass otherClass;
otherClass.pList = mainClass.List;
now, if I add items to the list in MainClass , the other pointer in MyOtherClass will not point to the good item; it will point to the item that MainClass.pList was pointing at the time it was assigned.
is there an easy way to have the pointer pList in MyOtherClass always point to the same thing that the pointer pList in MainClass ?
One way to fix this would be to insert at the end; that will keep the head of the MainClass list.
One other way could be do something like : ( this seems to work in the small test I did )
class MyOtherClass
{
MyList** pList;
};
MyOtherClass.pList = &mainClass.pList;
but I can't do it in my application; the list belongs to a another class, and that implicate a lot of other problems.
Any other ideas ?
Thanks.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
MyList is the calss that manages the linked list right ? So, on of the member in it should be the head of your list.
When you store the address of this class in another pointer, they will both point to the same linked list object. Thus, if the head changes, it will change for both pointers as they both point to the same class.
Or maybe I misunderstood your question. Maybe show us the code for the MyList class, it will help.
|
|
|
|
|
Actually, after reading your reply, I now believe that YOU understood him and I did not. Shame on me
Cedric is right: Just make the list-head accessible from your List-Class. If you need the most recent element, have your List-Class store a pointer to it as well.
Anyway, the List-Class should manage access to its contents, not the containing classes.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
no, sorry, my mistake, MyList ( maybe the wrong name here ) is the head of a link list; not the container of the list itself.
class MyList
{
MyList* pNext;
}
so, in standard ( beurk ) C ...
MyList* pList = NULL;
MyList* p = new MyList;
p->next = NULL;
pList = p;
p = new MyList;
p->next = pList;
pList = p;
...
on solution that we found was to keep a reference to the list in the MyOtherClass class.
class MyOtherClass
{
MyList*& pList;
};
Thanks.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
If you invalidate the pointer in your main class, you will have to update it in the other class.
One other thing you could try: Have a function "getCurrentPointer" or whatever you want to call it, and store a MainClass* myMainClass in your "OtherClass". Then use "myMainClass->getCurrentPointer" to retrieve the actual object.
e.g. (c-like pseudocode):
class MainClass
{
private List myList
public List* getCurrentList()
}
class OtherClass
{
private MainClass* pMainClass
public void setMainClass(*MainClass)
}
and somewhere:
OtherClass myOtherClass
MainClass myMainClass
OtherClass.setMainClass(&myMainClass)
// Now, when you change your List, you always use
myOtherClass.pMainClass->getCurrentList()
Since you are not pointing to a data member of a MainClass object, but to the object itself, you can do about everything you want with the MainClass-List (except deleting it, of course) and still have a way to access the List from your other class.
Thats just an idea
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|