|
Does it work for other languages?
|
|
|
|
|
How i should i use CString::LoadString(IDS_STRING);
|
|
|
|
|
|
in continuation with try CStringW::LoadString!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
I am creating a logging .dll utility. Which shud support multithreading.
I am a bit confused about how shud I be handling multithreading using MUTEX.
From the application(using my dll) I can call initializelog() function which get's the necessary data from properties file etc, and logmin(),logmid() and logmax() functions which passes the messages to the dll to log. Now if I have many threads running in my application and each thread calls any of the above functions. It should pass the message and the thread ID to dll to log. I know the Mutex function which synhronises the threads. But am confused WERE and HOW to use this in my DLL to synchronise the threads one at a time.
Please help me out to solve this..
THANKS
|
|
|
|
|
I think the easiest way to go is to use a critical section. Are you using MFC ? If yes, you can use a CCriticalSection object, otherwise you can go with the plain CRITICAL_SETION (win32).
Basically what you would is the following: in your function that logs text in your file, you wrap your logging code with an access to a critical section. This will ensure that only one thread will be able to log data in the file at a certain point of time:
void CLogger::Log(....)
{
m_CriticalSection.Lock();
m_CriticalSection.Unlock();
}
m_CriticalSection is an object of CCriticalSection and has been instancied previously.
|
|
|
|
|
I will try to do this. But I would also request you to please suggest me using MUTEX.
THANKS
|
|
|
|
|
Please suggest me reagrding this using mutex.
THANKS
|
|
|
|
|
Why, you need Mutex and don't want to use critical section as suggested earlier.
[Using Mutex Objects (WIN32)^]
[CMutex (MFC)^] To access or release a CMutex object, create a CMultiLock or CSingleLock object and call its Lock and Unlock member functions
|
|
|
|
|
Haven't Googled yet [^], have 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
|
|
|
|
|
Hi Im having two structures as follow
struct TagModel
{
float SPV [900];
float SPV1 [900];
float IPV [900];
float ISV[900];
};
struct Mystruct
{
float SPV [900];
float SPV1 [900];
}
From first structure, just i need only first two variables,and values of all varaibles are stored in shared memory. I used BELOW coding to read from first strucutre and write to my strucuture.
htBackTrackFile = FileName;
no_bt = 1;
struct Mystruct *temp;
temp = (struct Mystruct*) malloc(sizeof(struct Mystruct));
DWORD fp = SetFilePointer( htBackTrackFile, (no_bt * sizeof(struct TagModel)) + 10,NULL,(DWORD)FILE_BEGIN );
Flag = ReadProcessMemory((HANDLE)GetCurrentProcess(),(struct TagModel*)First,temp, (DWORD)sizeof(struct Mystruct),(LPDWORD)&ReturnVal );
WriteFile( htBackTrackFile,temp,(DWORD)sizeof(struct Mystruct), (LPDWORD&ReturnVal,(LPOVERLAPPED)NULL );
When i check this in debug mode...it shows as
First->SPV[1] = 50.000 //Its the correct value. from Fisrt TagModel struct
But mystruct writes as
temp->SPV[1] = 4.50000 .
Where is the problem..totally it shows very different value.
Is it the correct way to read very few member varaibles from one main structure to another strucute???
Anu
|
|
|
|
|
actually to copy the required amount of data from one memory to other, <b>memcpy</b> should be enough. please try it.
good luck.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Anu_Bala wrote: Flag = ReadProcessMemory((HANDLE)GetCurrentProcess(),(struct TagModel*)First,temp, (DWORD)sizeof(struct Mystruct),(LPDWORD)&ReturnVal );
WriteFile( htBackTrackFile,temp,(DWORD)sizeof(struct Mystruct), (LPDWORD&ReturnVal,(LPOVERLAPPED)NULL );
You may had better code if you are not aware of those API's.
what about directly writting to file from First(TagModel struct) without a memory copy.
WriteFile(htBackTrackFile,First,(DWORD)sizeof(struct Mystruct), (LPDWORD)&ReturnVal,(LPOVERLAPPED)NULL )
Anu_Bala wrote: But mystruct writes as
temp->SPV[1] = 4.50000 .
how do you verified it. have you considered the below calculation, (no_bt * sizeof(struct TagModel)) + <big>10</big>
Anu_Bala wrote: SetFilePointer( htBackTrackFile, (no_bt * sizeof(struct TagModel)) + 10,NULL,(DWORD)FILE_BEGIN );
|
|
|
|
|
Hi,
I have tool bar in my application.
In the below piece of code:
if (!m_wndEAToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_RIGHT
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,CRect(0,0,0,0),IDW_EA_BAR) ||
!m_wndEAToolBar.LoadToolBar(IDR_TOOLBAR_EA))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
I have this machro IDW_EA_BAR defined in the MainFrm.h file as
#define IDW_EA_BAR 0xE800
I could not determine what is this 0xE800. However from the article: http://book.chinaz.com/C/Visual%20C++%206.0/ch12/ch12.htm[^] I have the explaination for that parameter in the CreateEx function as : "you can specify any defined ID that you need or want to use for the toolbar. default - AFX_IDW_TOOLBAR"
However, I could not find any resource defined with that IDW_EA_BAR. And in MSDN also I could not find any explaination regarding the AFX_IDW_TOOLBAR.
Basically, I need to know what is the use of that parameter. In my piece of code why is it defined with that id in .h file? and why with that particular number?
Thanks in advance.
Priya Sundar
modified on Monday, May 19, 2008 6:57 AM
|
|
|
|
|
IDW_EA_BAR is user defined. and for AFX_IDW_TOOLBAR please Click here->[^] For MSDN answer.
AFX_IDW_TOOLBAR : The toolbar's child-window ID.If you do not want to use the default id than you may use user defined.
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Priya_Sundar wrote: #define IDW_EA_BAR 0xE800
Priya_Sundar wrote: I could not determine what is this 0xE800
Actually IDW_EA_BAR == 0xE800 == AFX_IDW_TOOLBAR, same value.
Priya_Sundar wrote: However, I could not find any resource defined with that IDW_EA_BAR
It is the not resource Identifier, it is the child window Identifier, for example Dialog Child window such as a Button can have an ID. since the tool bar is created dynamically using CreateEx and as a child window of the Frame window, you need to specify the child window ID. If the window has unique ID you can get the handle of the window specifying the ID using [GetDlgItem^] or pass to any GetDlgItemxxx funtions. If you have Handle to the window the control ID can be retrieved using [GetDlgCtrlID^].
And Since it is a ToolBar and if it is the child of Frame window you can gain access to the control bar specifying the ID using [CFrameWnd::GetControlBar^].
Priya_Sundar wrote: Basically, I need to know what is the use of that parameter
It is the unique Identifier of the child window so that you can gain access to the window from its parent window.
Priya_Sundar wrote: I could not find any explaination regarding the AFX_IDW_TOOLBAR
It is the standard ID of the main toolbar of a frame specified by MFC, so that it handles default standard command handling, such as toggling the visibility of toolbar when user clicks the menu command with ID, ID_VIEW_TOOLBAR. If you are adding new toolbar or specify different ID other than AFX_IDW_TOOLBAR, then you need to handle the command handling. see [TN022: Standard Commands Implementation ^], [TN021: Command and Message Routing ^]
|
|
|
|
|
Hey thanks a lot.
Priya Sundar
|
|
|
|
|
Hi,
I tried to return an interface but it gave me this error:
Unable to cast COM object of type 'MyTestLib.MainTestClass' to interface type 'MyTestLib.IMainTest '. This operation failed because the QueryInterface call on the COM component for the interface with IID '{519A413A-2792-4021-847F-B7C205FFE057}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Any idea why?
Here is my IDL:
import "oaidl.idl";
import "ocidl.idl";
[ object, uuid(EC23249E-2891-4f06-9D6E-77895E74448F) ] interface IAdd : IUnknown
{
HRESULT SetFirstNumber(long nX1);
HRESULT SetSecondNumber(long nX2);
HRESULT DoTheAddition([out,retval] long *pBuffer);
};
[ object, uuid(519A413A-2792-4021-847F-B7C205FFE057) ] interface IMainTest : IUnknown
{
HRESULT GetAddObject([out,retval] IAdd **ppObj);
};
[ uuid(AA484B10-6099-4e37-AEE3-8B4ADFBE2815) ] library MyTestLib
{
importlib("stdole32.tlb");
[ uuid(82B76786-E89B-4e42-8C50-B7916FEC1ADC) ]
coclass AddClass
{
[default] interface IAdd;
}
[ uuid(E76E5E58-F9D9-4570-AEC5-79A72E8E8743) ]
coclass MainTestClass
{
[default] interface IMainTest;
}
};
Thanks for any help
|
|
|
|
|
I found the problem. Apparently I am trying to be really smart about this by creating only 1 Factory and put a check in CreateInstance() to determine whether it is AddClass or MainTestClass.
I was wrong because the IID check should be in DllGetClassObject().
I have created 2 different factories for these classes and it works fine. I can now return the AddClass by using GetAddObject() function.
However, when I tried to use the function in AddClass (eg. SetFirstNumber()), it gave me this error:
The runtime has encountered a fatal error. The address of the error was at 0x7f628678, on thread 0x105c. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
Here is my code:
HRESULT __stdcall CMainTestClass::GetSamTest(IAdd **ppRetVal)
{
CAddClass *pAddClass = new CAddClass();
*ppRetVal = pAddClass;
return S_OK;
}
Thanks again for any help
|
|
|
|
|
how to get an integer value given by user in the editbox???
Raja
|
|
|
|
|
Like previous you can use of GetWindowText or GetDlgItemInt.
|
|
|
|
|
its given that,GetDlgItemInt(),function translates the text of a specified control in a dialog box into an integer value,but i need to get the integer value entered by user in the editcontrolbox and print the value,what should be done.
Raja
|
|
|
|
|
Why you cant use of this code:(do you like to hard work? atof, atoi, GetWindowText...)
int a;
a=GetDlgItemInt(IDC_EDIT1);
|
|
|
|
|
|
Hi,
CString strVal;<br />
EditBoxVar.GetWindowText(strVal);
Then use the following routines for conversion from string to int, float or long,
atof, atoi, atol .
Regards,
Paresh.
|
|
|
|
|