|
Yeah. Actually, another team wrote the code that searches for the window, and I believe it does use FindWindow. There is a nifty API you can call to see if a plug and play is happening, but it only works for 2K and XP. So I think we're stuck using FindWindow.
Ack! I hate 9X.
Even a broken clock is right twice a day.
|
|
|
|
|
Why not use ::EnumWindows() instead of FindWindowEx() ?
Navin wrote:
Ack! I hate 9X
me too!
I prefer to wear gloves when using it, but that's merely a matter of personal hygiene
[Roger Wright on VB]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
[Rich Cook]
|
|
|
|
|
Actually, I think the problem is in EnumWindows, becuase FindWindow apparently calls EnumWindows internally or something.
Even a broken clock is right twice a day.
|
|
|
|
|
I'm just going by this:
http://www.codeproject.com/cpp/avoidmultinstance.asp[^]
AFAIK, this guy knows his stuff, so I've been using EnumWindows instead f FindWindow[Ex].
GL!
I prefer to wear gloves when using it, but that's merely a matter of personal hygiene
[Roger Wright on VB]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
[Rich Cook]
|
|
|
|
|
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
si.cb = sizeof(si);
int rv = CreateProcess(exe, copyOfArgs, 0, 0, 0, 0, 0, 0, &si, &pi);
if (rv && wait)
{
unsigned long status = 0;
do
{
sleep(sleepDelay);
rv = GetExitCodeProcess(pi.hProcess, &status);
}
while ((status == STILL_ACTIVE) && rv);
}
if (pi.hProcess) CloseHandle(pi.hProcess);
if (pi.hThread) CloseHandle(pi.hThread);
NOTE: I have a custom sleep function that calls PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE); I ran into issues in multi-threaded apps.
Todd Smith
|
|
|
|
|
I need a help in DLL area. My co-worker is passing me a Carray data type into my dll and that seem to cause a "access violation error" in his exe when he tries to delete that Carray value. When I look into his program, it seem to failing at FreeLibrary call. It was detecting an memory error there. So, I made up a sample program to talk to the dll and it was fine. He is using sometype of Active X component and I am not sure if that may have something to do with it but I was going to see if any of you guys had a problem with passing MFC datatype into Dll. I tried it through MFC extention dll and regular Dll and both failed in same way. Any information would help me. Thanks!
My DLL side:
extern "C" __declspec(dllexport)
int InitProcess(LPSTR lpPortName, HWND hWnd, CArray<cmdarray,cmdarray &=""> *pMsg)
{
pMsg->ADD(type);
return 1;
}
Co-worker's Main side:
CArray <cmdarray,cmdarray> *m_pCmdArray;
m_pCmdArray = new CArray <cmdarray,cmdarray &="">();
typedef int (* LPFNINITPROCESS)(LPCSTR,HWND, CArray <cmdarray,cmdarray &=""> *);
LPFNINITEPROCESS lpfnInit;
lpfnInit lpfnInitProcess;
hLib = LoadLibrary("MYDLL.dll");
lpfnInitProcess((LPCSTR)COMPORT, this->m_hWnd, m_pCmdArray);
FreeLibrary(hLib); <------------------ memory leak detect;
delete m_pCmdArray; <------------------ access viloation error... yack..
|
|
|
|
|
keb wrote:
extern "C" __declspec(dllexport)
int InitProcess(LPSTR lpPortName, HWND hWnd, CArray *pMsg)
{
pMsg->ADD(type);
return 1;
}
Co-worker's Main side:
CArray *m_pCmdArray;
m_pCmdArray = new CArray ();
typedef int (* LPFNINITPROCESS)(LPCSTR,HWND, CArray *);
LPFNINITEPROCESS lpfnInit;
lpfnInit lpfnInitProcess;
hLib = LoadLibrary("MYDLL.dll");
lpfnInitProcess((LPCSTR)COMPORT, this->m_hWnd, m_pCmdArray);
FreeLibrary(hLib); <------------------ memory leak detect;
delete m_pCmdArray; <------------------ access viloation error... yack..
This is not a paste and cut example code snippet, I can't see any call to GetProcAddress()
Give us the whole code... perhaps it has to do with MFC and regular DLLs... hm..
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
The memory leak being detected is because the object that is added to the array (inside InitProcess) is allocated by the DLL but not freed by the DLL. I assume you're adding multiple elements to the array, right? Because if it's only one, then you don't need an array. The bottom line is that if the DLL is that one allocating the memory, it must also be the one freeing it.
The access violation I'm not sure of, since there's a lot of code missing from your sample. Try posting it again but leave a space after the opening angle bracket and before the closing one (for the template parameters). Also, what is "type"? You don't show where it came from.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Wow, I can't get over the fact how quickly I get some help. Thanks guys. And here is more of the code we used which is failing. I guess I should have just cut and paste rather than typing things in... Also the idea behind here is that I am trying to que up a message that I recieve from a hardware and my co-worker is trying to read message and get rid of the memory space after he reads. What would be the best way to achieve this? Is creating a dll to do this work bad idea?
co-workers' side:
void CViapcDlg::OnConnect()
{
char errMsg[MAX_PATH];
DWORD result;
hLib=LoadLibrary(COMMDLLNAME);
DLL_LOAD = TRUE;
if(hLib==NULL)
{
AfxMessageBox(errMsg);
DLL_LOAD = FALSE;
}
else
{
char COMPORT[MAX_PATH];
int comport;
memset(COMPORT,0,MAX_PATH);
m_pHDContainer = new THDContainer();
m_pCommandArray = new CArray <tcommandarray,tcommandarray &="">();
m_pCommandArray->SetSize(0, 10);
m_pHDContainer->ONLINE = false;
for(int i =0; i < 5; i++)
{
if(m_COMPort[i]->GetCheck())
comport = i+1;
m_COMPort[i]->EnableWindow(FALSE);
}
wsprintf(COMPORT, "\\\\.\\COM%d", comport);
lpfnInit = (LPFNINIT)GetProcAddress((HMODULE)hLib, "InitProcessor");
lpfnClose = (LPFNCLOSE)GetProcAddress((HMODULE)hLib, "CloseProcessor");
lpfnProcessor = (LPFNPROCESSOR)GetProcAddress((HMODULE)hLib, "Processor");
lpfnAdd = (LPFNADD)GetProcAddress((HMODULE)hLib, "Add");
if(lpfnInit)
result = lpfnInit((LPCSTR)COMPORT, this->m_hWnd, m_pHDContainer, m_pCommandArray);
}
}
void CViapcDlg::OnMessage(WPARAM wparam, LPARAM lparam)
{
while(m_pCommandArray->GetSize())
{
TCommandArray insertData = m_pCommandArray->GetAt(0);
m_pCommandArray->RemoveAt(0);
do things with data here...
}
}
void CViapcDlg::Close()
{
if(hLib)
FreeLibrary((HMODULE)hLib); <----------- Memory leak here
if(m_pHDContainer)
{
delete m_pHDContainer;
}
if(m_pCommandArray)
{
delete m_pCommandArray; <---------- Access violatioin error here
}
}
My side:
int InitProcessor(LPSTR lpPortName, HWND hWnd, THDContainer *pHDContain, CArray <tcommandarray,tcommandarray &=""> *pHDMsg)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
thread stuff here to get info from a hardware and add stuff into array;
TCommandArray data;
data.type1 = 1;
data.type2 = 2;
data.type3 = 3;
pHDMsg->add(data);
::PostMessage( hWnd, COMDLL_MESSAGE, 0, 1);
return 0;
}
|
|
|
|
|
Again, some of the code is missing because the template parameters (for CArray) are wiped out by the HTML interpreter. The easiest way to avoid it is to put a space after the opening bracket and before the closing bracket: CArray< type1, type2 >.
Here are some points to consider:
1. The memory leak I already explained why it occurs.
2. The access violation I'm still not sure of, since it's not clear where m_pCommandArray is created and if your CViapcDlg::Close() is being called multiple times. A word of advice, after deleting a pointer variable, always set it to NULL. This ensures that if you delete it again, it's not pointing to bogus memory and the program doesn't blow up.
3. The question of whether or not to use a DLL in this case is best answered by you. Is the code in the DLL reusable by other apps? Or perhaps, do you intend to "plug in" a different set of source code into your app at run-time, similar to a driver? If the answer to either of these is Yes, then a DLL is the way to go. If not, then it's not worth it. You'll only complicate your life unnecessarily, as you're seeing now.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Hi All,
I'm having some issues with the MDI. I have a recent file list in my application. Problem is I need to perform some custom open operations on the file that is opened from the Recent File List.
My problem is the Recent File List doesn't call the function my function OnFileOpen. What do I need to override in order to intercept the recent file list opening process?
any suggestions are greatly appreciated.
Thank you
|
|
|
|
|
Override OnOpenRecentFile
Gary Kirkham
A working Program is one that has only unobserved bugs
|
|
|
|
|
I did that in both my CBlahBlahApp and in the CMainFrame. Neither worked. I'm implementing an MDI doc/view and I am using VC++ 6.0.
Any more suggestions are greatly appreciated.
Thank you.
|
|
|
|
|
It should work...
place
afx_msg BOOL OnOpenRecentFile(UINT nID);
in your header before DECLARE_MESSAGE_MAP()
place
ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnOpenRecentFile)
in your message map in your implemetation file (.cpp)
and add a function
BOOL Cblahblahapp::OnOpenRecentFile(UINT nID)
{
// calling this will implement standard file open
CWinApp::OnOpenRecentFile(nID);
}
works when I do it...post some code
Gary Kirkham
A working Program is one that has only unobserved bugs
|
|
|
|
|
Gary Kirkham wrote:
place
ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnOpenRecentFile)
in your message map in your implemetation file (.cpp)
Ah Ha! I totally forgot to add the messages to my message map.
That did the trick! Thank you!
Dan
|
|
|
|
|
Hello everyone.
I use a list control(in MFC) with subitems(0,1,2,3),it works fine until i call DeleteAllItems.After this function is executed if i try to insert a new item only the subItem 0 is inserted.HELP!!!! THANKS
|
|
|
|
|
One solution is to insert the first item and implement SetItem() for all subitems.
Kuphryn
|
|
|
|
|
Hi,
I would like to read/write datas from TCP/IP.
I looking for little samples or litteratures.
Best Regards,
youssef
|
|
|
|
|
There are many samples here at this site. Take a look at http://www.codeproject.com/internet/
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
A great book is called "UNIX Network Programming vol. 1" by the late Richard Stevens. Don't be discouraged by it's title. It uses the berkeley socket API which is a part of the Winsock API. If you learn the berkeley socket API, you won't have any problems learning Winsock.
Furthermore, Stevens was a great author indeed. He uses many easy to grasp examples to show how everything works, inside out. He also wrote the TCP/IP Illustrated series which I also recommend.
--
Only in a world this sh*tty could you even try to say these were innocent people and keep a straight face.
|
|
|
|
|
Hi, guys!
Could somebody please help!!!
I got such piece of code:
CMyMenu : public CMenu<br />
{<br />
public:<br />
virtual void DrawItem(LPDRAWITEMSTRUCT) {some code;}<br />
virtual void MeasureItem(LPMEASUREITEMSTRUCT){some code;}<br />
};<br />
<br />
<br />
CMainFrame::OnCreate()<br />
{<br />
...<br />
<br />
m_MyMenu.LoadFrame(IDR_MAINFRAME);
<br />
m_MyMenu.GetSubMenu(0)->ModifyMenu(0, MF_BYPOSITION | MF_OWNERDRAW, (UINT)(HMENU)m_MyMenu, _T("R-r-r"));<br />
<br />
SetMenu(&m_MyMenu);<br />
}
And I got "R-r-r" instead of "&File", with CMyMenu::DrawItem() called just fine. But "R-r-r" is truncated, as CMyMenu::MeasureItem() is not called for it.
Why?
Thanks
|
|
|
|
|
Because the function's signature should be:
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
For some reason, everytime i go to "Start Without Debugging", it tells me that my project configurations are out of date. Even after a complete rebuild? Has anyone else ever had this issue? Even after it rebuilds and runs, it tells me that the configuration is out of date, without a single source change? What gives?
Ryan Baillargeon
|
|
|
|
|
I have had that happen to me before, although probably not to the extent that you might have. One thing I did notice was that for some reason, if I had certain project files open, it would always say the files were out of date. Perhaps you could try closing all visible files(not the project itself), and try again. If that's not it, then I really don't know what is.
<NOTE:This message in no means reflects the actuall thoughts, concerns, or opinions of the author, the president, or the rat living in your walls. Please do not take it seriously, jokingly, lovingly, or at all.>
"Don't tell me I'm smart, I might actually believe you!"
"I once knew a guy who said he was a coder...The FBI arrested him two days later."
|
|
|
|
|
Damn, that didnt work...
- could it be that theres a file in the build configuration that is changing post build? therefore necessitating a new build every time?
Ryan Baillargeon
|
|
|
|
|