|
Yes, and before this I just knew how to calculate areas and those things using C++. So, it is a huge difference hahaha
|
|
|
|
|
I have a need for creating a class template and you may help me.
[1] Multiple coclasses will be implemented in a single dll.
[2] Each coclass will implement the same interfaces but will have different class/clsid/resid.
[3] It is necessary to create a class template taking clsid/resid as its template paramemters.
[4] Finally, I need to use template classes for CoCreateInstance.
Let me elaborate more in detail.
Here is a simple interface IA defined.
interface IA : IDispatch
{
[id(1), helpstring("method M1")] HRESULT M1();
};
Below ia a coclass defined with Class(CComX), Clsid(CLSID_ComX), Resid(IDR_COMX).
It implements Intid(IA).
class ATL_NO_VTABLE CComX
: public CComObjectRootEx<ccomsinglethreadmodel>,
, public CComCoClass<comx, clsid_comx="">
, public IDispatchImpl
{
CComX();
~CComX();
BEGIN_COM_MAP(CComX)
COM_INTERFACE_ENTRY(IA)
COM_INTERFACE_ENTRY2(IDispatch, IA)
END_COM_MAP()
DECLARE_REGISTRY_RESOURCEID(IDR_COMX)
...
}
OBJECT_ENTRY_AUTO(CLSID_ComX, CComX)
Next, I need to create second coclass implementing the same interface IA but having different Class(CComY), Clsid(CLSID_ComY), and Resid(IDR_COMY).
So, I simply copied the above coclass and replaced 'X' with 'Y'.
class ATL_NO_VTABLE CComY
: public CComObjectRootEx<ccomsinglethreadmodel>,
, public CComCoClass<ccomy, clsid_comy="">
, public IDispatchImpl<ia, &iid_ia,="" &libid_comtlib,="" *wmajor="*/" 1,="" *wminor="*/" 0="">
{
CComY();
~CComY();
BEGIN_COM_MAP(CComY)
COM_INTERFACE_ENTRY(IA)
COM_INTERFACE_ENTRY2(IDispatch, IA)
END_COM_MAP()
DECLARE_REGISTRY_RESOURCEID(IDR_COMY)
...
}
OBJECT_ENTRY_AUTO(CLSID_ComY, CComY)
And I successfully CoCreateInstance'd these two coclasses:
HRESULT hr = S_OK;
ULONG rc = 0;
IA *pXA = NULL;
hr = CoCreateInstance(CLSID_ComX, NULL, CLSCTX_ALL, IID_IA, (void **)&pXA);
rc = pXA->Release();
IA *pYA = NULL;
hr = CoCreateInstance(CLSID_ComY, NULL, CLSCTX_ALL, IID_IA, (void **)&pYA);
rc = pYA->Release();
So far so good!
The problem is that I need to create many coclasses now and in the future.
I don't want to copy/paste for all of them because it is quite hard to maintain the source code for all the copy/paste'd coclasses. It is quite error-prone.
So, I definitely would like to create a class template.
Below, I created a class template and it compiled ok.
template
class ATL_NO_VTABLE CComT
: public CComObjectRootEx,
, public CComCoClass, &CLSID_T>
, public IDispatchImpl
{
CComT()
{
}
~CComT()
{
}
BEGIN_COM_MAP(CComT)
COM_INTERFACE_ENTRY(IA)
COM_INTERFACE_ENTRY2(IDispatch, IA)
END_COM_MAP()
DECLARE_REGISTRY_RESOURCEID(RESID_T)
...
}
//OBJECT_ENTRY_AUTO(CLSID_ComT, CComT)
I hope I am doing right.
Next, I would like to instantiate two template classes to replace the original CComX and CComY classes:
class CComT<clsid_comx, idr_comx="">;
class CComT<clsid_comy, idr_comy="">;
Is this right way to instantiate template coclasses?
And if so, how would I modify the above CoCreateInstance statements?
I have ComT.zip file containing all these classes but don't know how to upload here.
So, if you give me your email, I would send it.
thank you
|
|
|
|
|
Hi
I'm trying to compile a c++ project on a raspberry pi using g++. I get the following compilation error:
PROCESS.CPP: In function ‘int process(int, char*, ControlData*, char*, char*)’:
PROCESS.CPP:172:49: error: ‘_fullpath’ was not declared in this scope
PROCESS.CPP:185:45: error: ‘_fullpath’ was not declared in this scope
The file PROCESS.CPP has the header
#include <stdlib.h> which I thought should contain this declaration. I have checked the header path using the g++ -H command and it gives /usr/include/stdlib.h so I presume it is finding the file.
I don't want to start fiddling with my own declarations within the scope as there are many other files to include in this project.
Any help would be appreciated
|
|
|
|
|
The message says it is not declared in this scope, and identifies lines 172 and 185 as being where the error occurs. You need to look at those two lines to see what may be the reason.
|
|
|
|
|
_fullpath is a Microsoft specific library function that does not exist on Unix systems. You may use the realpath[^] function instead.
[EDIT/UPDATE]
Because pathes are different on Unix and MS operating systems, the function call can't be simply replaced. I assume that you are tyring to compile some source that has been originally written for a Microsoft OS. You have to analyse the code and rewrite it to get similar behaviour on your Pi.
|
|
|
|
|
Aha! Thanks Jochen
I'll look into that: the clue was there with the underscore?
|
|
|
|
|
You are welcome.
The underscore is a clue because it is not used with Unix libraries (at least the common ones). To get the description for standard library functions on your Pi just type "man <function_name>". I was quite sure that fullpath does not exist and checked it this way.
|
|
|
|
|
Thanks - I really appreciate it!
|
|
|
|
|
Hi,
I have one query. I want to get the Login and Logout Time of a user. I want to get the time when user login to a pc, lock the PC, Logout (shutdown) the PC. I want to keep track of the Login / logout / Locking time of the user. Is there any class or any code available in C++ / MFC.
Any help will be appreciated.
Regards,
|
|
|
|
|
|
mbatra31 wrote: I have one query. I want to get the Login and Logout Time of a user. Have you considered using NetUserGetInfo() with USER_INFO_2 ? It has a usri2_last_logon and usri2_last_logon field.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hello David,
Thanks for sharing the info. It was very helpful.
I have one query again. this function gives the Last logon and Logoff time in the number of seconds that have elapsed since 00:00:00, January 1, 1970, GMT. How can I get the correct value in Time format.
Also I want to get the record of user logon and logoff time for each day. Should I use the same function.?
Regards,
|
|
|
|
|
This is Unix time (UTC) use the time functions. For an example see[^].
|
|
|
|
|
mbatra31 wrote: I have one query again. this function gives the Last logon and Logoff time
in the number of seconds that have elapsed since 00:00:00, January 1, 1970, GMT.
How can I get the correct value in Time format. Converting time since that epoch was something I learned very early on in my career (some 25 years ago). It's worth the effort at figuring it out (without the help of Google).
mbatra31 wrote: Also I want to get the record of user logon and logoff time for each day.
Should I use the same function.? Since the above is always referenced from a fixed point in time, you'd need to "capture" it once per day. Admittedly, there may be a log somewhere that Windows keeps where it writes an entry for every time a user logs in/out of a workstation. I've never had the need to know so I can't tell you if this is true or not.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hi I have created a menu using Resource.
for example-->
A
and below I want to add one menu named B dynamically.
How to do that.
|
|
|
|
|
CMenu menu;
menu.LoadMenu(IDR_RESOURCEMENU);
CMenu* pContextMenu = menu.GetSubMenu(1);
pContextMenu->InsertMenu(0, MF_STRING | MF_BYPOSITION, ID_LISTMENU_OPEN, _T("&Open"));
pContextMenu->InsertMenu(1, MF_SEPARATOR | MF_BYPOSITION, 0); pContextMenu->SetDefaultItem(0, TRUE);
ID_LISTMENU_OPEN must declared somewhere in your app, as UINT
Hope it help you ...
|
|
|
|
|
<a href="http://www.codeproject.com/Members/flaviu">@Flaviu</a>u
Thanx for the reply
Its not working for me
void CmainWn::OnBZ()
{
// TODO: Add your command handler code here
CMenu menu;
menu.LoadMenuA(IDR_MENU1);
CMenu* pcontextmenu=menu.GetSubMenu(0);
pcontextmenu->InsertMenuA (0,MF_STRING|MF_BYPOSITION,ID_SHOW,_T("&Open"));
pcontextmenu->InsertMenuA(1,MF_SEPARATOR|MF_BYPOSITION,0);
pcontextmenu->SetDefaultItem(0,TRUE);
}
I added this code on the event handler of menu Z which is under menu B at location 0.
But it is not working for me.
My objective is here is on the click of menu Z one menu should be added in my main menu(IDR_MENU1) named as A
Correct me If I am wrong somewhere.
|
|
|
|
|
You should explain better: what you call "Menu Z" ? If I understand well, you have a resource menu, IDR_MENU1, where you want to add dynamically an menu item, ID_SHOW ... I am right ?
P.S. If you post code, use tag ...
|
|
|
|
|
<a href="http://www.codeproject.com/Members/flaviu">@Flaviu</a>u
I have defined Menu Z its entry in resource file is
ID_B_Z .
Yes you are right I am having a resource menu IDR_MENU1 where I want to add a menu named ID_SHOW dynamically.
I just want to know what is wrong with my code ?
|
|
|
|
|
How you defined ID_SHOW ?
|
|
|
|
|
@Flaviuu
Yes I have defined it in my Resource.h file like this.
#define ID_SHOW 107
|
|
|
|
|
Use CMenu::InsertMenuItem that allows you to insert a menu item, an image, a submenu or whatever you want. See[^].
|
|
|
|
|
Thakur JAI SINGH wrote: But it is not working for me. What specifically is not working? You have 5 statements here. Have you stepped through each one using the debugger to see which one is not working as expected?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
So I have a thread, thread one, that writes a byte (an ACK) to a COM port (COM over USB), then sets an event, and a thread, thread two, that's waiting on that event with WaitForSingleObject, INFINITE, which then writes 7 bytes to the port, then goes back to waiting again. Thread one, then reads data from the port, and when its got the whole chunk, writes the ACK, sets the event, and so it goes round again. ad infinitum.
Now I have a USB analyser on the wire, so I can see the timing here, between the one byte ACK going out, and the 7 bytes of data, and it is sometimes 4 seconds!
4 seconds? One thread does a SetEvent, and the other thread, doing a WaitForSingleObject takes 4 seconds to get notified?
Dont believe me?
613 . 0x06 8 2/23/2015 5:52:20.593552 PM
614 .ABCD.. 0x02 58 56 45 52 03 1a 14 2/23/2015 5:52:24.094321 PM
See, almost 4 seconds, that's the USB sniffer trace. What the hells going on?
Just seen one trace go by, and its 8 seconds!
I mean, cant MSFT tighten it up a bit? This is appaling!
( By the way, the driver is mine, and the time between the IRP_MJ_WRITES of 1 byte, and 7 bytes, also reflects the large gaps seen on the USB bus. The driver traces when its hit by the app calling WriteFile() so its not a problem in the driver either, it really is the thread scheduling. )
|
|
|
|
|
If this were true, there would be A LOT of very slow programs out there.... you likely have some other bug in the code. Signaling should be pretty fast.
You'll need to post some source if you want any help though...
|
|
|
|
|