|
|
You could use the api ReadDirectoryChangesW() as well. Check here[^] for code snippet.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hi,
I am running a WinCE6.0 Stream interface Driver on a DTE device which will open a handle to Serial port which is
connected to a modem.WriteFile API returns non-zero Value, but NumberofbytesWritten parameters is coming as Zero.
The Windows CE 6.0 device is a DTE terminal and when connected to PC (Another DTE)) over NULL Modem cable with hyperterminal, all the data from the are seen on the hyperterminal, and WriteFile API fills the NumberofbytesWritten is exactly the same as the
bytestoWrite.
When the CE6.0 DTE device is connected to DCE Modemdevice using a Straight serial cable, WriteFile API
is succedding by returning Non-Zero Value, but NumberofbytesWritten parameters is coming as Zero.
The following is the DCB in the driver:
dcb.BaudRate = m_BaudRate;(115200)
dcb.fBinary = TRUE;
dcb.fParity = TRUE;
dcb.fOutxCtsFlow = TRUE;
dcb.fOutxDsrFlow = FALSE;
dcb.fDtrControl = DTR_CONTROL_ENABLE;
dcb.fDsrSensitivity = FALSE;
dcb.fTXContinueOnXoff = TRUE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
dcb.fErrorChar = FALSE;
dcb.fNull = FALSE;
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
dcb.fAbortOnError = FALSE;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
Also, I am setting EscapeCommFunction(m_hCOMHandle,SETDTR);
On the hyperteminal I have the following setting:
baudrate = 115200
Data bit = 8
Parity=None
StopBit=1
FlowControl=None
Also, with the same hyperterminal setting with PC(Hyperterminal) connected to Modem over Straight SErial cable,
I am able to fire the AT Commands from the PC(hyperterminal) to the modem.
Also CommTimeout, I have set the following:
CT.ReadIntervalTimeout = MAXDWORD;
CT.ReadTotalTimeoutMultiplier = 0;
CT.ReadTotalTimeoutConstant = 0;
CT.WriteTotalTimeoutMultiplier = 0;
CT.WriteTotalTimeoutConstant = 100;
-Can a timeout issue cause WriteFile Still succeed and Numberof Bytes Written as zero?
- In hyperterminal Flow Control None, what are the Flow control affected in the DCB?
Can somebody give me some hints on the same.
Thanks..
|
|
|
|
|
My project is SDI project and I add some dialog in this project.
In this dialog I need to access some variable in CDocument class so I write this code
CTestDoc* pDoc = (CTestDoc*)GetDocument();
I got this error
"Error 3 error C3861: 'GetDocument': identifier not found"
Although I #include "TestDoc.h" at begining of file the error is same
Please advise me how to solve this problem.
|
|
|
|
|
You're trying to call a function called GetDocument() that doesn't exist
in the context of where you're calling it from.
If you're calling it from within your dialog class code then you need to
implement a method called GetDocument - CDialog doesn't have one.
A few ways to implement this:
Pass a reference to your document into the dialog.
Make the document globally accessible.
Use a CFormView instead of a CDialog. CForm view has a GetDocument().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm working on a GSM application where i'm supposed to send a text msg using AT commands by detecting a com port, however before simulating the comp port i would like to know how we can detect the whether which com port is available.
|
|
|
|
|
|
Hi.
How can I create a working thread in a MFC regular dll and How can I load such a dll in a application?
Never Change My Goal!
|
|
|
|
|
First make sure you've covered the requirements for a regular DLL
that uses MFC (taken from the docs):
1) Compiled with _USRDLL defined, and if the DLL links to MFC dynamically,
_AFXDLL must be defined.
2) The DLL must instantiate a CWinApp-derived class.
3) The DLL uses the DllMain provided by MFC. Don't add your own.
Place all DLL-specific initialization code in the InitInstance
member function and termination code in ExitInstance as in a normal
MFC application.
In the dll you can use AfxBeginThread() to create worker threads.
If you don't know how to actually use a DLL, you may want to study:
DLLs[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark.
But When I did it as you said,it does not seem to work at all!
can you give me some example code?
Never Change My Goal!
|
|
|
|
|
Not working how?
Please list any compiler errors, linker errors, runtime exceptions, etc.
To start with, are you able to successfully call a function in your DLL?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
there is no compiler errors,linker errors..
the dll loads successfully,and I can call the function in the dll too.
and here is the funtion in the dll:
UINT threadproc(LPVOID lparam)
{
::MessageBox(NULL,"call the function succeefully","info",MB_OK);
return 0;
}
extern "C" void __declspec(dllexport) dllext()
{
::MessageBox(NULL,"call the function succeefully in dllext()","info",MB_OK);
CWinThread*pThread=AfxBeginThread(threadproc,NULL,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED ,NULL);
pThread->ResumeThread();
}
and here is the function in a normal MFC application:
void CMainFrame::OnBeginthread()
{
typedef void (*Pdllfun)();
HINSTANCE hdll=LoadLibrary("thread.dll");
if(hdll==NULL)
::MessageBox(NULL,"can not laod the dll","",MB_OK);
Pdllfun pdllfun=NULL;
pdllfun=(Pdllfun)::GetProcAddress(hdll,"dllext");
if(pdllfun==NULL)
::MessageBox(NULL,"can not laod the dll funion","",MB_OK);
pdllfun();
FreeLibrary(hdll);
}
if I do not call the pThread->ResumeThread() function which in the dll,everything will be ok.
but once I call the pThread->ResumeThread() function,the main application will crash.
and the errors it returns to me is:
0x00fd102d instruction references "0x00fd102d" memory can not be written
Never Change My Goal!
modified on Monday, November 10, 2008 3:27 AM
|
|
|
|
|
The fact that you're using LoadLibrary to load the dll at run time makes a HUGE difference to your question.
In this case, I wouldn't go any near MFC for the DLL at all, just plain vanilla Win32.
I can see one gaping problem though - after you've called resume thread, you return from dllext(), and the promptly call FreeLibrary (). That will (as the name says...) free the library. As you only loaded it once, that will also unload it from your memory. Then windows does a context switch (or could have done at any time - or even simultaneously) to your thread. Which tries to run code that doesn't exist anymore...
Imagine Wile E Coyote running off a cliff, running into mid air for a few seconds, looking down... that's what you've done to your code.
Iain.
|
|
|
|
|
thanks Iain.I have solved the problem.
The fact that you are right!
void CMainFrame::OnBeginthread()
{
typedef void (*Pdllfun)();
HINSTANCE hdll=LoadLibrary("thread.dll");
if(hdll==NULL)
::MessageBox(NULL,"can not laod the dll","",MB_OK);
Pdllfun pdllfun=NULL;
pdllfun=(Pdllfun)::GetProcAddress(hdll,"dllext");
if(pdllfun==NULL)
::MessageBox(NULL,"can not laod the dll funion","",MB_OK);
pdllfun();
::MessageBox(NULL,"hold the dll","",MB_OK);
FreeLibrary(hdll);
}
so..thanks Iain again!!
Never Change My Goal!
|
|
|
|
|
Iain Clarke wrote: Imagine Wile E Coyote running off a cliff, running into mid air for a few seconds, looking down... that's what you've done to your code.
Excellent!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Iain Clarke wrote: I wouldn't go any near MFC for the DLL at all, just plain vanilla Win32.
If he's truly properly implemented a "regular DLL linked to MFC" as
described here[^]. there should ne no problems.
Probably some thread synchronization issues in the near future for kim_wu...
Thanks for handling the remainder of this thread!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I got two questions.
1 - Which is the preferred way of using the pointer symbol(*). Is it along with the type or with the identifier?
int* intPtr
OR
int *intPtr; IMO, the second one is more clear when we declare something like this.
int *intPtr1,intPtr2; 2 - Is it a good practice to append const with member function that doesn't modify any member variables?
int foo::sampleMethod() const{
} I understand why const member functions exists. But if we are not planning to make the class object as constant, do we need this kind of declarations?
Any help would be great.
|
|
|
|
|
I personally prefer the int* intPtr; But I declare a single variable in a line. This way I can add a comment for each variable I use.
I do add const to each member function that doesn't modify member variables. The problem is you can almost never predict how the class is going to be used at a later time. Once I had to add const to loads of member function for about 10-20 classes. Also, I am not sure, but in certain cases adding const might help compiler to produce more optimized code.
-Saurabh
|
|
|
|
|
Saurabh.Garg wrote: But I declare a single variable in a line. This way I can add a comment for each variable I use.
Saurabh.Garg wrote: The problem is you can almost never predict how the class is going to be used at a later time.
Good points.
Saurabh.Garg wrote: I am not sure, but in certain cases adding const might help compiler to produce more optimized code.
Do you have any articles/books which explains this?
Thanks for your help
|
|
|
|
|
you have an interview, don't you ?
Christian Flutcher wrote: 1 - Which is the preferred way of using the pointer symbol ?
for me, I like to declare every variable separatedly, and I don't like to mix declarations of different types.
this way, I prefer using int* pi; syntax because I see immediately that pi is of type int*.
Christian Flutcher wrote: 2 - Is it a good practice to append const with member function that doesn't modify any member variables?
definitely, yes !
because the one who write the class is not always the one who will use it, a class definition has to be clear, and has to mean what the class is designed for.
When you have an accessor which just does a "get", the it's obviously not modifying the object, and should be declared as const.
Christian Flutcher wrote: I understand why const member functions exists. But if we are not planning to make the class object as constant,
humm, it seems to me that you don't fully understand the thing.
making a function member constant doesn't mean every function members have to be consts, and it doesn't mean either that the object will be used as a constant.
If you'd like to say that the object is used as a constant, then you would have to do like this :
<font color="blue">class</font> foo { ... };
<font color="blue">const</font> foo f(<font color="green"></font>);
|
|
|
|
|
toxcct wrote: you have an interview, don't you ?
No I don't have. I just finished reading "Thinking in C++" and about to start a project in C++. So thought of getting some expert advice on those points.
Thanks for you help. It was really helpful.
|
|
|
|
|
1/ I normally do:
int *pInt;
2/ the question you ask is why I never mix those. And if the variable it at all significant, it gets its own line. I use long variable names - thanks to intellitext they're just as easy to type, and a lot easier to read. Only loop vars get bunched together. int i,j,k;
3/ I try to use const on member functions that *shouldn't* modify the state, not whether I think I might do so. It gives me the freedom to change my mind in one direction, and makes it harder to code mistakes in the other.
Iain.
|
|
|
|
|
Perfect ! Thanks for the help Iain.
|
|
|
|
|
|
Can you elaborate? Format what like this?
-Saurabh
|
|
|
|