|
Thanx for the help
|
|
|
|
|
You can also use the _access C runtime function.
Cheers,
Tom Archer
Author, Inside C#
Please note that the opinions expressed in this correspondence do not necessarily reflect the views of the author.
|
|
|
|
|
You can also use the _access C runtime function.
But please don't do it. Either use ANSI C functions, ISO C++ functions or native functions. Mixing in POSIX (which is a half-breed in Win32 land - fits like a foot in a glove) makes no sense.
|
|
|
|
|
You're going to have to do a lot better than that. Exactly why does it make "no sense"?
Cheers,
Tom Archer
Author, Inside C#
Please note that the opinions expressed in this correspondence do not necessarily reflect the views of the author.
|
|
|
|
|
CString strDirectory = "...";
CFileStatus fileStatus;
if (CFile::GetStatus (strDirectory, fileStatus)) {
if (fileStatus.m_attribute & CFile::directory) {
...
}
}
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
This was quite handy! Thanks.
J
"I am wise enough to therefore not spout my ill informed opinion as if it were remotely related to fact." - Christian Graus
|
|
|
|
|
Glad to help, Jamie. Actually I'm working on a CP article that will collect all file/dir handling methods into a single class. Stay tuned!
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Dear Buddies,
Do you have any experience of programming two kind
of common dialog boxes: PageSetup dialog and Print
dialog? My problem is about the margin Rect retrived from
PageSetup dialog, I don't know how to apply this rect
to Print dialog box because of the unit. I have tried
"milimeter" or "inches", but they don't work. Does anyone
know how-to or the relative sample codes? thanks!
--------------
Ask the experts always.
|
|
|
|
|
Have you tried "mm" or "in"?
|
|
|
|
|
How can I get the net adapter address?
all the adapter is validate, but at some machine, I can get the adapter address,
at some machine, I cann't (address is all Zero).
The codes:
-----------------------------------------------------------
#include <nb30.h>
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff[30];
} ASTAT;
void getNetID()
{
NCB ncb;
UCHAR ch;
memset(&ncb,0,sizeof(ncb));
ncb.ncb_command = NCBRESET;
ch = Netbios(&ncb);
// at some machine, ch = NRC_BRIDGE 0x23 // ncb_lana_num field invalid
memset(ncb.ncb_callname,' ',sizeof(ncb.ncb_callname));
ncb.ncb_callname[0] = '*';
//lstrcpy(ncb.ncb_callname,"* ");
ncb.ncb_command = NCBASTAT;
ASTAT AST;
ncb.ncb_lana_num = 0;
ncb.ncb_length = sizeof(AST);
long *pASTAT;
pASTAT = (long *)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY, ncb.ncb_length);
if ( pASTAT == 0 )
{
AfxMessageBox("memory allocation failed!");
return;
}
ncb.ncb_buffer = (unsigned char *)pASTAT;
ch = Netbios(&ncb);
CopyMemory(&AST, ncb.ncb_buffer, sizeof(ASTAT));
CString str( _T("") );
for(int i=0; i<6; i++)
{
if( i > 0 )
str += ' ';
unsigned char c = (unsigned char)AST.adapt.adapter_address[i];
unsigned char m = (c>>4)&0xf;
unsigned char n = c&0xf;
str += (m>=10) ? (char)('A'+(m-10)) : (char)('0'+m);
str += (n>=10) ? (char)('A'+(n-10)) : (char)('0'+n);
}
HeapFree(GetProcessHeap(), 0, pASTAT);
AfxMessageBox( str );
}
---------------------------------------
What's wrong?
Thanks
|
|
|
|
|
Are you trying to get the MAC address of the Ethernet Adapter or the IP address?
|
|
|
|
|
Just want to get the adapter unique id!
Thank you
|
|
|
|
|
Ok ... I want to have Tabs
on all my MDIClients of my
application so all I need to
do is this ....
In my CMainFrame::OnCreateClient method I add the lines
...
tab = new MyTab();
tab.AddItem(this)
...
right?
Wrong of course.
What should I be doing?
I have looked at all the examples
on TabControls none of them
are what I need and I really don't
understand MFC.
Please help you might "win" a convert.
(pardon the pun)
|
|
|
|
|
check out the doc/view section here on cp
there are a few very good articles / frameworks for what you want
situations to avoid #37: "good morning ... how many sugars do you take in your coffee ... and what was your name again?"
coming soon: situations to avoid #38: "...and the dog was there too?"
|
|
|
|
|
Thanks for the info ... but the examples there
are pretty much the same. They have MDI "client"
brought to the front by clicking on a tab in the
MDI "main frame". I would like to have the
tabs inside the "client".
I can see that having the tab on the "main frame"
has its advantages but that is not what my user
wants.
Here's what i am trying to do ...
http://www.codeproject.com/useritems/newtomfcneedhelp.asp
Thanks
|
|
|
|
|
I embedded the WebBrowser control in my app... couple questions:
In Internet Explorer whenever the user navigates to a new page,
the logo up in the top right hand corner (on the same level as the
menu) rotates between a globe and the start symbol. How can I add
something like that to my app? Would I use the CAnimateCtrl or whatever
it's called? How doe I get it on the same level as the menu bar in
my app? I have a dialog based app... in case that's important.
When I run my app and browse to a page, it loads fine. But then
whenever I hit the Escape key on the keyboard, the whole WebBrowser
control disappears. If I enter a new URL in my ComboBox and hit the
Go button, then the WebBrowser control reappears. How can I make it
so the Escape key does not make the WebBrowser control disappear?
thanks,
thundercatzlair
|
|
|
|
|
Hi, folks,
I got some problems for multi-threading/multiple instances with one thread function. What's wrong with the following code segment.
In some cases, I got wrong instance as showed below. The case is: if I have 2 jobs triggered, say Job 1 and Job 2, Job 1 is triggered first but Job 2 would be done first (i.e, done prior to Job 1). Then, when Job 2 Set event (i.e, set to signaled state), I found in Master Thread Function,
in the line of WaitForSingleObject(..), what I got is Job 1's instance and Job 1's event ? Could anyone tell me how to solve this problem ? Anything wrong ? Thanks in advance.
PS> I do need to wait for events, because I have more than one tasks to do and I need to wait until all tasks are done, although in this small code, it seems just one task.
/// JOBINST: my job instance
DWORD WINAPI StartJob( JOBINST pJobObj )
{
pJobObj->hMasterThread( 0, 0, MasterThreadFunc, pJobObj, 0, &( pJobObj->dwMasterThreadID ) );
}
DWORD WINAPI MasterThreadFunc( LPVOID lpParam )
{
JOBINST pJobObj = (JOBINST) lpParam;
pJobObj->hMailEvent = CreateEvent( 0, FALSE, FALSE, "Mail Thread Event" );
pJobObj->hMailThread = CreateThread( NULL, 0, MailThreadFunc, pJobObj, 0, &( pJobObj->dwMailThreadID ) );
WaitForSingleObject( pJobObj->hMailEvent, INFINITE );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
///<------ In some cases, I got wrong pJobObj and wrong pJobObj->hMailEvent here
CloseHandle( pJobObj->hMailEvent );
ExitThread( 0 );
}
DWORD WINAPI MailThreadFunc( LPVOID lpParam )
{
JOBINST pJobObj = (JOBINST) lpParam;
//// do something here...
//// when finished with something, set event; set to signaled state
SetEvent( pJobObj->hMailEvent );
ExitThread( 0 );
}
|
|
|
|
|
Sorry, just typo... the correct one is as follows:
DWORD WINAPI StartJob( JOBINST pJobObj )
{
pJobObj->hMasterThread = CreateThread( 0, 0, MasterThreadFunc, pJobObj, 0, &( pJobObj->dwMasterThreadID ) );
}
|
|
|
|
|
Could you setting the event on SetEvent(pJobObj->hMailEvent) before WaitForSingleObject()? Do a simple test add:
Sleep(100); before //// do something here!
Let me know...
Al
|
|
|
|
|
>Could you setting the event on SetEvent(pJobObj->hMailEvent) before >WaitForSingleObject()? Do a simple test add:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Why ? Originally, the pJobObj->hMailEvent is on non-signaled state. And, when the MailThreadFunc() is finished, I set this event to signaled state.
So, I can NOT put SetEvent(pJobObj->hMailEvent) before WaitForSingleObject() in MasterThreadFunc(). (Is this what you mean ?)
>Sleep(100); before //// do something here!
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Al:
In fact, I have a Sleep(5000) right before SetEvent(pJobObj->hMailEvent) in MailThreadFunc(..).. Same result as I described.
|
|
|
|
|
I don't know then!
Looks good to me.
Sorry!
Al
|
|
|
|
|
That isn't a problem with events unless you use something like PulseEvent.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
It looks like it would be a problem in how you are managing your job pointers. You have them stored in a std::vector?
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
>>It looks like it would be a problem in how you are managing your job >>pointers. You have them stored in a std::vector?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No, I did not use std::vector. I use my own linked list (queue) to store my job pointers. And, when I try to remove the "store operation" to list (i.e, now I did not keep these job pointers), same thing. So, I guess the problem should be on the thread or thread function ?
But the above code is fine in this case: job 1 is triggered before job 2 and, job 1 is also "done" before job 2.
I still don't know why.
|
|
|
|
|
I got it already ! Thanks for everybody's reply.
JOBINST pJobObj = (JOBINST) lpParam;
pJobObj->hMailEvent = CreateEvent( 0, FALSE, FALSE, "Mail Thread Event" );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Wrong for the event string - "Mail Thread Event" !!
Every event should be unique !
So, the correct one is something like this:
char strMailEvent[ 64 ];
wsprintf( strMailEvent, "MyMailEvent %x",( DWORD )pJobObj );
pJobObj->hMailEvent = CreateEvent( 0, FALSE, FALSE, strMailEvent );
because every pJobObj is unique (allocated from heap), I use this as key for every event.
|
|
|
|
|