|
|
can you write the code of it here?
|
|
|
|
|
If you took the trouble to go and look at the links that Cool_Dev provided you would see some sample code to help you.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Note that people sometimes forget about FindClose() thus leaking a handle. Another important thing is that when FindFirstFile() returns INVALID_HANDLE_VALUE and when FindNextFile() returns FALSE you may want to check if GetLastError() returns ERROR_NO_MORE_FILES or something more brutal.
|
|
|
|
|
void txt2cpp(const TCHAR* path)
{
TCHAR full[_MAX_PATH+_MAX_FNAME];
TCHAR move[_MAX_PATH+_MAX_FNAME];
unsigned int flen;
unsigned int mlen;
HANDLE hf;
WIN32_FIND_DATA fd;
_tcscpy(full,path); flen = _tcslen(full); _tcscpy(full+flen,_T("\\*.txt"));
hf = FindFirstFile(full);
if(INVALID_HANDLE_VALUE!=hf)
{
do
{
if(!(FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes))
{
_tcscpy(full+flen+1,fd.cFileName);
_tcscpy(move,full); mlen = _tcslen(move);
for(;(0<mlen)&&('.'!=move[mlen-1]);mlen--);
_tcscpy(move+mlen,_T("cpp"));
MoveFile(full,move);
}
} while(FindNextFile(hf,&fd));
FindClose(hf);
}
}
comment: not safe for buffer overflow.
|
|
|
|
|
|
When using MFC, we can create dll usign MFC, and create MFC dialog or MFC windows in DLL. And Shows the dialog or windows by export functions.
But how to use WTL in dll? WTL AppWizard can only create exe project, ATL has no enough UI support. What can we do to usign WTL in dll? Create WTL dialogs and WTL windows and other WTL UI components.
Thanks
|
|
|
|
|
Hi,
tank0 wrote: What can we do to usign WTL in dll?
WTL is a template library and as you certainly know templates are compiled when used, not when declared. Thus it is impossible to export uninstanciated template classes from a dll.
That said, you can use WTL in dlls which export only fully instanciated templates like WTL_DLL.ZIP
in the Files section of the WTL support list[^].
Another example is here[^].
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Alain Rist wrote: WTL is a template library and as you certainly know templates are compiled when used, not when declared. Thus it is impossible to export uninstanciated template classes from a dll.
That said, you can use WTL in dlls which export only fully instanciated templates like WTL_DLL.ZIP in the Files section of the WTL support list[^].
Another example is here[^].
cheers,
AR
Thanks for your reply. What I what to do is just like you said.
Export a single function in the dll such as ShowDlg()
What the ShowDlg function do is that creates a modal window and shows.
With MFC, I can just create a "Regular DLL with MFC statically linked" project and in the project use codes like below is enough.
But I don't know what to do with WTL. WTL appwizard can only create exe projects.
extern "C" __declspec(dllexport) void ShowDlg()
{
CDialog dlg(IDD_Dialog1);
dlg.DoModal();
}
|
|
|
|
|
Use an AppWiz generated Win32 dll with the code from a WTL application. Study the referenced WTL_DLL.ZIP code, it's really simple and does exactly what you wish
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
I got it, thanks for your help
|
|
|
|
|
You are welcome
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Hi ,
I am creating BHO component in which I used DWebBrowserEvents2 interface and overrides its
OnQuit() function. When i test this function on IE8 on Vista, it called on my machine but does not called on other machine with same configuration. What may be the problem for not calling onQuit() function on other machine.
Does this mean that IE8 is not installed properly on other machine, or there is need to installed windows update for this.
please let me know how IE8 behavior change from machine to machine.
Thanks
Atul
|
|
|
|
|
Documentation states OnQuit 'Fires before the Windows Internet Explorer application quits'. May be you can check if the IE has actually quit.
|
|
|
|
|
I am writing an application wherein I need to scan the computer to see if either of two different USB devices are attached. The first device appears as a HID, and the second device appears as a virtual COM port. Which WMI classes should I be checking to see if each device is attached?
I am using this for the HID:
m_bstrScope = SysAllocString( _T("root\\CIMV2") );
m_bstrQuery = SysAllocString( _T("SELECT PNPDeviceID FROM Win32_PnPEntity") );
...and this for the virtual COM port device:
m_bstrScope = SysAllocString( _T("root\\CIMV2") );
m_bstrQuery = SysAllocString( _T("SELECT DeviceID,PNPDeviceID FROM Win32_SerialPort") );
This pseudo code shows how my scanning algorithm works:
if ( ScanForDevice1() )
{
}
else if ( ScanForDevice2() )
{
}
else
{
}
This seems to work, except when I change which device is connected between running the application. If device 1 is found, the scan for device 2 is aborted; the scan for device 2 only occurs if device 1 is not found. What happens is this:
- The application is run with both devices attached to the system. Device 1 is found, as expected. The application exits.
- Device 1 is unplugged from the system.
- The application is run with only device 2 attached to the system. Oddly, device 1 is found, even though it is not attached. The application exits.
- Both devices are unplugged from the system.
- The application is run with no devices attached. No devices are found, as expected. The application exits.
- Only device 2 is plugged back into the system.
- The application is run with only device 2 attached. The application finds device 2, as expected.
My best guess is that I am querying the wrong class(es). Which classes should my application be checking? Or, is there something else that I should be doing? Thanks.
|
|
|
|
|
one com interface function :
class IProtocolImp : public IUnknown
{
.....
GetRegisters( char *szDeviceName[int], LPVOID *ppReg[out] , int *pRegNum[out] );
// Get registers name and number
......
}
typedef struct reginfo
{
char sRegName[8];//register's name
int nLowIndex;
int nUpperIndex;
WORD wDataType;//
int nData;
}REG_INFO;
i call this in my project,
IProtocolImp * pf;
int RegNum;
REG_INFO * BASED_CODE pRegInfos[256];
HRESULT res=::CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,IID_ProtocolImp,(void * *)&pf);
if(res == S_OK)
{
pf->GetRegisters("MyDevice",(LPVOID *)pRegInfos,&RegNum);
}
if program is correct,will return
RegNum=2;
gsRegInfos[0]={"DATA1", 0, 15, 100, 0};gsRegInfos[1]={"DATA2", 0, 15, 100,0};
but program has a problem,
RegNum=2;//this correct
gsRegInfos[0]={"DATA1", 0, 15, 100, 0};gsRegInfos[1]=0xcccccccc;//this a problem
why ????
it is com code:
"xxx.h"
static REG_INFO BASED_CODE gsRegInfos[]=
{
{"DATA1", 0, 15, 100, 0};
{"DATA2", 0, 15, 100, 0};
};
"xxx.cpp"
STDMETHODIMP_(BOOL) MYDLLPro::XProtocolImp::GetRegisters(char *szDeviceName,LPVOID * ppRegs, int *pRegNum)
{
METHOD_PROLOGUE(MYDLLPro, ProtocolImp);
*ppRegs = (LPVOID)&gsRegInfos;
*pRegNum = sizeof(gsRegInfos)/sizeof REG_INFO;//REG_TYPE_NUM
return TRUE;
}
|
|
|
|
|
It's not easy to read your question. Please edit the message and put <pre></pre> tags around he code blocks so they can be read more easily. From a quick glance it looks like your indexing is not working properly, check the pointer indexing in your GetRegisters() function.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Perhaps if you formatted your code so it's readable?
Steve
|
|
|
|
|
I'm a new one, which want to learn linux. but i do't how to study it.
i have use ubuntu some days.but i find i use it like windows. i don't
understand somethings about linux,but just use g++.
I want to be a coder in linux, so give me some advices , thank you very
much
|
|
|
|
|
Here, perhaps this will get you started: Programming for Linux[^]
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
In my current VS C++ app I create an fstream log file for output and all works fine. It's initialized in the constructor declaration. Now I want to close it and start a new one upon the log file reaching a size limit. I've tried a number of things with no success. One approach was to not initialize in the constructor and use .open. That didn't work. Another was to go back to initialize in the constructor, then close, and rename, and open again. That didn't work either. Either I am missing some key point here or just doing some samll thing incorrectly. Any help would be appreciated.
Thanks
|
|
|
|
|
Alan Kurlansky wrote: That didn't work.
This sort of statement is really not very helpful; nobody can guess why it did not work. Explain exactly what you did and what results you got, if there is a short code snippet that helps with the explanation then include that as well. And don't forget to put code between <pre></pre> tags.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Sorry about that. But I was able to get things to work by reducing the scope of the file management. Now I am opening, closing, renaming the file all from within a function, using all local and local static variables.
|
|
|
|
|
Why "FlatSB" is useless in WTL?
::InitializeFlatSB,::FlatSB_EnableScrollBar,::FlatSB_SetScrollProp...return 0.
Create a Dialog(or Edit Control、List Control...),
Set show HorizontalScrollBar and VerticalScrollBar,
in OnInitDialog(...):
BOOL bRet = ::InitializeFlatSB(m_hWnd);
bRet = ::FlatSB_EnableScrollBar(m_hWnd,SB_BOTH,ESB_ENABLE_BOTH);
bRet = ::FlatSB_SetScrollProp(m_hWnd, WSB_PROP_VSTYLE, FSB_FLAT_MODE, TRUE);
bRet = ::FlatSB_SetScrollProp(m_hWnd, WSB_PROP_HSTYLE, FSB_FLAT_MODE, TRUE);
// change scrollbar color
bRet = ::FlatSB_SetScrollProp(m_hWnd, WSB_PROP_HBKGCOLOR, 0x008000ff, TRUE);
bRet = ::FlatSB_SetScrollProp(m_hWnd, WSB_PROP_VBKGCOLOR, 0x0000ff80, TRUE);
this works on MFC!
|
|
|
|
|
Hi,
dancingfish wrote: Why "FlatSB" is useless in WTL?
WTL support for flat scroll bars in atlctrls.h:
#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
template <class T>
class CFlatScrollBarImpl
{
template <class TBase>
class CFlatScrollBarT : public TBase, public CFlatScrollBarImpl<CFlatScrollBarT< TBase > >
{
typedef CFlatScrollBarT<ATL::CWindow> CFlatScrollBar;
As Comctl32.dll versions 6.00 and later do not support flat scroll bars check (WTL::RunTimeHelper::IsCommCtrl6() == false) before use
cheers,
AR
Edit: Added CommCtrl version check suggestion.
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
modified on Wednesday, November 10, 2010 5:15 AM
|
|
|
|
|