|
GetModuleFileName()
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Im trying to setup my app so that when a user right clicks on a associated file type then selects "run with myApp" itll open my app passing the files full path. Ive tried getCommandLine() and directly accessing m_lpCmdLine but both of these return the short file name.
|
|
|
|
|
I'm not certain how do do exactly what you want, but couldn't you call GetLongPathName function once you know the short filename and convert it to the long name?
|
|
|
|
|
Unless he's calling a "short file name" just the "file name" as in x.exe. I've seen this that sometimes you get a full path in the command line and sometimes you just get the exe name.
If you want to get the path to the current executable, which is what you want? You don't want to trust the command line.
To get the path to the location of the exectuable (or DLL) use "GetModuleFileName" or "GetModuleFileNameEx". Those should get you the path to the executable.
|
|
|
|
|
Thank you very much! GetLongPathName was exactly what i needed.
Just out of curiosity, do you have any idea why id be getting a short filename? I manually setup the registry so that when someone right clicked on the file type it ran my program and passed the file as a parameter. Whenever my program would get the command line data itd be in the form:
<long path="" as="" i="" specified="" in="" the="" registry=""> <short path="" of="" the="" file="" selected="">
and by short path i mean the old school dos type w/ ~'s in the path
|
|
|
|
|
Glad the workaround worked for you. I'm sorry I don't know the proper way to do this...I haven't done any shell programming at all. I did find this article on the codeguru; not that I recommend or endorse the codeguru in any way - seeing that I'm a loyal codeproject user:
http://www.codeguru.com/Cpp/COM-Tech/shell/article.php/c1315/
|
|
|
|
|
Hi, I'm currently using Visual Studio .NET 7.0. But some of the new projects I download are made for just 7.1, and I was wondering if it was possible to update 7.0 to 7.1 in the first place?
Thanks
|
|
|
|
|
|
Hi
Here is my Full code in which i am creating a thread in DLL and passing the function name as ThreadFunc . But it is not going to the ThreadFunc after creating it. See the Func PrepareThread() below
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C" __declspec(dllexport) BOOL Connect ( char *pPort , char *pBuff )
{
int nDataSize = 0;
int nSentSize = 0;
if(strcmp(pPort,"") == 0)
{
strcpy(pBuff,"Please supply a COM port");
return false;
}
g_hPort = Rs232Open(pPort);
if ( l_bTaskAbort )
{
Rs232CleanUp(FALSE);
return false;
}
if ( g_hPort == NULL )
{
l_dwErrCode = GetLastError();
ShowRegError(l_dwErrCode);
Rs232CleanUp(FALSE);
return false;
}
// wake up printer
char wakeUpChars[2];
wakeUpChars[0]=(char)'0x0H';
wakeUpChars[1]='\0';
nDataSize = strlen(wakeUpChars);
nSentSize = Rs232SendBlk(g_hPort, wakeUpChars, nDataSize);
Sleep(100);
if ( l_bTaskAbort )
{
Rs232CleanUp(FALSE);
return(false);
}
//Lets check for oneil printer attached or not
nDataSize = 6;
nSentSize = Rs232SendBlk(g_hPort,"\x1b{ST?}",nDataSize);
if(nSentSize != nDataSize)
return false;
// Sleep(100);
char szData[36];
memset(szData,0x00,sizeof(szData));
if(Rs232RecvBlk(g_hPort,szData,35 ) >0)
{
if(strncmp(szData,"{ST!E:N;",8) != 0)
{
strcpy(pBuff,"Printer is not connected.");
return false;
}
}
else
{
strcpy(pBuff,"Printer is not connected.");
return false;
}
return true;
}
extern "C" __declspec(dllexport) BOOL ReadCard(char *pData)
{
if(g_hPort == NULL)
{
strcpy(pData,"COM port is not opened");
return false;
}
PrepareThread();
return true;
}
extern "C" __declspec(dllexport)void Disconnect()
{
//Terminate Read thread and close msr3000
TerminateThread(g_hThreadRead, 0);
g_hThreadRead = NULL;
Rs232CleanUp(FALSE);
}
DWORD WINAPI ThreadFunc(LPVOID param)
{
BOOL bSuccess = TRUE;
while(1)
{
int index = 0;
// Clear the dara buffer first.
memset(g_strResult,0x00,500);
if ( l_bTaskAbort )
{
Disconnect();
return(false);
}
//if card is seated
// Ask the user to remove the card
// if the card is removed then read the data
if(GetCardData())
{
//MyMSR_ShowResult(0);
break;
}
}
return bSuccess;
}
static void PrepareThread()
{
g_hThreadRead = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc, 0, 0,&dwThreadID);
}
static BOOL GetCardData()
{
BOOL bSuccess = TRUE;
char szData[100];
int nDataSize = 0;
int nSentSize = 0;
DWORD dwStartTime;
dwStartTime = GetTickCount();
szData[0] = 0x1B;
szData[1]='{';
szData[2]='M';
szData[3]='R';
szData[4]='?';
szData[5]='}';
szData[6]='\0';
nDataSize = strlen(szData);
while ( !l_bTaskAbort )
{
DWORD dwEllapsedTime = GetTickCount() - dwStartTime;
//time out
if ( dwEllapsedTime >= READTIMEOUT )
{
bSuccess = FALSE;
break;
}
nSentSize = Rs232SendBlk(g_hPort, szData, nDataSize);
if ( nSentSize != nDataSize )
{
bSuccess = FALSE;
break;
}
Sleep(100);
if( Rs232RecvBlk(g_hPort, g_strResult, 500) >0)
{
// No card data
if(strncmp(g_strResult,"{N}",3) == 0)
{
Sleep(10);
}
else
{
break;
}
}
else
{
Sleep(10);
}
}
return bSuccess;
}
//----------------------------------------------------------------------------
// Rs232Open
//----------------------------------------------------------------------------
static HANDLE Rs232Open(char *pPort)
{
DCB PortDCB;
HANDLE hPort;
BOOL bSuccess = FALSE;
COMMTIMEOUTS CommTimeouts;
PortDCB.DCBlength = sizeof(DCB);
hPort = CreateFile(pPort,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if ( hPort == INVALID_HANDLE_VALUE )
{
l_dwErrCode = GetLastError();
return NULL;
}
// set up detail
SetupComm(hPort,INQUEUESIZE,OUTQUEUESIZE);
bSuccess = GetCommState(hPort,&PortDCB);
if (bSuccess == FALSE)
{
l_dwErrCode = ERROR_NOT_READY;
CloseHandle(hPort);
//if (g_hStatus != NULL)
// SetWindowText(g_hStatus, TEXT("Err setting Comm"));
return NULL;
}
//CBR_9600, CBR_19200,CBR_38400,CBR_57600,CBR_115200
PortDCB.BaudRate = CBR_9600;
PortDCB.fBinary = TRUE;
PortDCB.fParity = TRUE;
PortDCB.fOutxCtsFlow = FALSE;
PortDCB.fOutxDsrFlow = FALSE;
PortDCB.fDtrControl = DTR_CONTROL_ENABLE;
PortDCB.fDsrSensitivity = FALSE;
PortDCB.fTXContinueOnXoff = TRUE;
PortDCB.fOutX = FALSE;
PortDCB.fInX = FALSE;
PortDCB.fErrorChar = FALSE;
PortDCB.fNull = FALSE;
PortDCB.fAbortOnError = FALSE;
PortDCB.ByteSize = 8;
PortDCB.Parity = NOPARITY;
PortDCB.StopBits = ONESTOPBIT;
PortDCB.fRtsControl = RTS_CONTROL_ENABLE;
PortDCB.XoffLim = INQUEUESIZE/5;
PortDCB.XonLim = INQUEUESIZE/5;
bSuccess = SetCommState(hPort,&PortDCB);
// set time out
bSuccess = GetCommTimeouts(hPort,&CommTimeouts);
CommTimeouts.ReadIntervalTimeout = MAXDWORD;
CommTimeouts.ReadTotalTimeoutMultiplier = 0;
CommTimeouts.ReadTotalTimeoutConstant = 0;
CommTimeouts.WriteTotalTimeoutMultiplier = 0;
CommTimeouts.WriteTotalTimeoutConstant = 3000;
bSuccess = SetCommTimeouts(hPort,&CommTimeouts);
if ( l_bTaskAbort )
{
l_dwErrCode = ERROR_NOT_READY;
CloseHandle(hPort);
// if (g_hStatus != NULL)
// SetWindowText(g_hStatus, TEXT("Err setting timeout"));
return(NULL);
}
Sleep(1000);
PurgeComm(hPort,PURGE_TXCLEAR|PURGE_RXCLEAR);
return(hPort);
}
//----------------------------------------------------------------------------
// Rs232SendBlk
//----------------------------------------------------------------------------
static int Rs232SendBlk(HANDLE hPort, LPSTR lpcData, int nSize)
{
int nLen = 0;
DWORD dwWrite;
l_dwErrCode = ERROR_SUCCESS;
while ( ( nLen < nSize ) && !l_bTaskAbort )
{
if ( !WriteFile(g_hPort,lpcData+nLen,nSize-nLen,&dwWrite,0) )
{
l_dwErrCode = GetLastError();
dwWrite = 0;
}
if ( dwWrite == 0 )
{
break;
}
nLen += dwWrite;
}
return(nLen);
}
//----------------------------------------------------------------------------
// Rs232RecvBlk
//----------------------------------------------------------------------------
static int Rs232RecvBlk(HANDLE hPort, LPSTR lpcData, int nSize)
{
int nLen = 0;
DWORD dwRead;
DWORD dwStartTime;
l_dwErrCode = ERROR_SUCCESS;
dwStartTime = GetTickCount();
while ( ( nLen < nSize ) && !l_bTaskAbort )
{
DWORD dwEllapsedTime = GetTickCount() - dwStartTime;
if ( dwEllapsedTime >= l_dwTimeout )
{
return(nLen);
}
if ( !ReadFile(g_hPort,lpcData+nLen,nSize-nLen,&dwRead,0) )
{
l_dwErrCode = GetLastError();
dwRead = 0;
}
if ( dwRead > 0 )
{
nLen += dwRead;
dwStartTime = GetTickCount();
}
else
{
Sleep(10);
}
}
return(nLen);
}
//----------------------------------------------------------------------------
// Rs232CleanUp
//----------------------------------------------------------------------------
static int Rs232CleanUp(BOOL bSuccess)
{
//l_bTaskAbort = TRUE;
// If there is an open port
if ( g_hPort != NULL )
{
PurgeComm(g_hPort,PURGE_TXABORT|PURGE_TXCLEAR|PURGE_RXABORT|PURGE_RXCLEAR);
// Close the port
CloseHandle(g_hPort);
// Mark it not open
g_hPort = NULL;
}
// Indicate that Rs232 shutdown is complete
l_bTaskDone = TRUE;
// Return what was passed in
return(bSuccess);
}
void ShowRegError(DWORD nReturnVal)
{
LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
nReturnVal,
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, TEXT("Error"), MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );
}
|
|
|
|
|
You'll get much more favorable responses by providing only relevant code. No one likes spending their time wading through code that is not part of the problem.
How are you verifying that ThreadFunc() is not being called?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I am putting the Break Point in the ThreadFunc() but it is not going to that function.
Shailesh
|
|
|
|
|
aman2006 wrote:
I am putting the Break Point in the ThreadFunc()
On the BOOL bSuccess = TRUE statement, I assume? If so, could it be possible that the primary thread is terminating before the secondary thread has had a chance to start up?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I want to write one function in which I want to pass Computer Domain, Account Name, Password and absolute path of any one directory or file. From this four parameters I want to find out whether the entered user has privileges to get content of given file or directory or he is impersonating other user or such things...
Can any one help me ...Any function that you think will be helpful to me or any link which contain such similar example or any material to read ...plz I m waiting eagrly for it..
Thanking You
Chuy Ji Lee.
|
|
|
|
|
You want to do this on NTFS?
Security is a big pain, but this is what I think you have to do.
First, you need to get the security descriptor (The DACL is what you want I think) of the file. You can do this with "GetFileSecurity".
Then you need to have an access token of the client. If this is an RPC call, the user has already called in this context. You can call like "ImpersonateUser()" and then get the user's token with GetToken or something I forget the function, and you can then use one of the "AccessCheck" functions to check if that user has access. You can also call "LogonUser" since you have the password and username to get the user's token I believe. Those are the functions I'm pretty sure you want to look into.
|
|
|
|
|
Thanks a lot dear
Your answer helped me a lot.
Thank you again
Bye
|
|
|
|
|
Hi,
I am trying to implement a 'Help' file/dialogue (the standard Microsoft kind with the purple book in the L-hand corner). I have so far used the MFC Application Wizard, and selected that I do want a 'Help file' before beginning (the initialization process where you select whether or not you want ActiveX support, comments in your code, whether your app is multiple documents or dialogue-based etc.)
I understand that the text in the Help file is located in AfxDlg.rtf
When you choose to add a Help file to your application (my application is dialogue-based with buttons), the MFC Wizard automatically adds a 'Help' button to your Dialogue Box GUI. When you click the 'Help' button, it supposedly loads 'AfxDlg.rtf' (a text file that says #<<your app="">> Help Index
<<write a="" topic="" here="" that="" discusses="" your="" application's="" main="" dialog="">>).
But, my problem is: after I edit AfxDlg.rtf, when I click the Help button,
it is the same 'original' document (the document with the original #<<your app="">> Help Index <<write a="" topic="" here="" ...),="" and="" it="" doesn't="" even="" seem="" to="" recognize="" my="" changes="" (i="" changed="" afxdlg.rtf="" read="" #<<my="" app="">> Help Index ...); Does anyone know how to make the changes to AfxDlg.rtf get recognized? Or how to add on to the Help file? Is it a matter of linking?
Or editing a certain header file?
Thanks alot for your time.
Regards,
Tim Hsieh
Trex Enterprises
my changes.
|
|
|
|
|
If the help SDK is installed correctly on your mahcine, and your MFC project built correctly originally, then each time you 'rebuild all' your Help file should be recompiled into the HLP file. The Help system does not load RTF files, it loads files 'compiled' into an HLP file. You should have an HPJ - help project file - that controls the building, and if you look, it should be part of your project, along with a couple other files related to help. Watch the build output window for something about 'microsoft windows help compiler' to go by, if it is missing, then your help file is not being recompiled as part of your project.
|
|
|
|
|
I'm using VC6 and creating a dialog in a DLL. I'm trying to add the Web Browser (ActiveX) Control to the dialog. I do this and a CWebBrowser2 class is automatically created for me. I use class wizard to add it as a member variable. But when I execute the code, the dialog will not show up. If I take the control out, it works. And if I try it in a dialog in an EXE, it works. Anyone have any ideas?
|
|
|
|
|
I'm writing an app and connects a computer to another peice of hardware via the serial port. I've got everything working however while writing my comm port settings to the registry, I found that I do not know how to determine what the flow control setting is set to. Has anyone worked with the flow control settings and know what from the DCB structure I'm suppsed to use that dertmines that?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
The documentation for the DCB structure did not help answer that question for you? Please explain how/why it is not sufficient.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
it does not directly tell you whether it is xon/xoff or hardware or none. Not sure what in the DCB I need to look to determine what the user has set that setting for.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Oh, sorry, didn't understand your goal.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Tom:
This is probably what you are looking for.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/dcb_str.asp
In particular:
(For XON/XOFF)
fOutX
Indicates whether XON/XOFF flow control is used during transmission. If this member is TRUE, transmission stops when the XoffChar character is received and starts again when the XonChar character is received.
fInX
Indicates whether XON/XOFF flow control is used during reception. If this member is TRUE, the XoffChar character is sent when the input buffer comes within XoffLim bytes of being full, and the XonChar character is sent when the input buffer comes within XonLim bytes of being empty.
fRtsControl
RTS (request-to-send) flow control. This member can be one of the following values. Value Meaning
RTS_CONTROL_DISABLE Disables the RTS line when the device is opened and leaves it disabled.
RTS_CONTROL_ENABLE Enables the RTS line when the device is opened and leaves it on.
RTS_CONTROL_HANDSHAKE Enables RTS handshaking. The driver raises the RTS line when the "type-ahead" (input) buffer is less than one-half full and lowers the RTS line when the buffer is more than three-quarters full. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function.
RTS_CONTROL_TOGGLE Specifies that the RTS line will be high if bytes are available for transmission. After all buffered bytes have been sent, the RTS line will be low.
Windows Me/98/95: This value is not supported.
fOutxCtsFlow
If this member is TRUE, the CTS (clear-to-send) signal is monitored for output flow control. If this member is TRUE and CTS is turned off, output is suspended until CTS is sent again.
And Possibly ...
fDtrControl
DTR (data-terminal-ready) flow control. This member can be one of the following values. Value Meaning
DTR_CONTROL_DISABLE Disables the DTR line when the device is opened and leaves it disabled.
DTR_CONTROL_ENABLE Enables the DTR line when the device is opened and leaves it on.
DTR_CONTROL_HANDSHAKE Enables DTR handshaking. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function.
fOutxDsrFlow
If this member is TRUE, the DSR (data-set-ready) signal is monitored for output flow control. If this member is TRUE and DSR is turned off, output is suspended until DSR is sent again.
Let me know if you need any other help, hopefully these are enough to get you by!
|
|
|
|
|
I understand what the MSDN is saying about this structure but my problem is that while the COMMCONFIG dialog box is returning back the users configuration choices, I do not see anything for flow control. For instance I know what the user choose for baud by looking at dcb.baudrate or for parity by looking at dcb.parity, but I do not know what to look at for flow control.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
How about something such as this:
if ((m_DCB.fRtsControl == RTS_CONTROL_HANDSHAKE) && (m_DCB.fOutxCtsFlow)) {
// CTS/RTS control is enabled (This is hardware flow control)...
}
if ( (m_DCB.fOutX) && (m_DCB.fInX)) {
// XON / XOFF is enabled (Software flow control)
}
If neither of the above statements are true, flow control (hardware and software) is disabled.
Hopefully that is what you are looking for.
|
|
|
|
|