|
i put
Find ( CString file , const CArray& FArray)
c:\program files\microsoft visual studio\myprojects\anaktisi\anaktisidlg.h(18) : error C2143: syntax error : missing ',' before '&'
c:\program files\microsoft visual studio\myprojects\anaktisi\anaktisidlg.h(18) : error C2059: syntax error : '&'
C:\Program Files\Microsoft Visual Studio\MyProjects\Anaktisi\AnaktisiDlg.cpp(850) : error C2955: 'CArray' : use of class template requires template argument list
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(238) : see declaration of 'CArray'
C:\Program Files\Microsoft Visual Studio\MyProjects\Anaktisi\AnaktisiDlg.cpp(851) : error C2511: 'Find' : overloaded member function 'double (class CString,const class CArray &)' not found in 'CAnaktisiDlg'
c:\program files\microsoft visual studio\myprojects\anaktisi\anaktisidlg.h(14) : see declaration of 'CAnaktisiDlg'
|
|
|
|
|
Immunity18 wrote: c:\program files\microsoft visual studio\myprojects\anaktisi\anaktisidlg.h(18) : error C2143: syntax error : missing ',' before '&'
Did you forget #include <afxtempl.h> in your project's stdafx.h file?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
#include "stdafx.h"
its the first of my include
|
|
|
|
|
Immunity18 wrote: #include "stdafx.h"
its the first of my include
Meaning what?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
i because it was <afx> it wasn't visible and i thought u said
did you forget to #include , in your project, the "stdafx.h" file ?
And yes i didnt #include "afxtempl.h"
but not that i forget ,because i didnt know i had :P
|
|
|
|
|
Now i include it my
double CAnaktisiDlg::FindDF(CString file , CArray < CString, CString > FArray)
works fine
thank you onces again David
(both kevin and mark )
|
|
|
|
|
Here's an example of how to pass an array argument from the CArray implementation in afxtempl.h
INT_PTR CArray<TYPE, ARG_TYPE>::Append(const CArray& src)
{
ASSERT_VALID(this);
ASSERT(this != &src);
if(this == &src)
AfxThrowInvalidArgException();
INT_PTR nOldSize = m_nSize;
SetSize(m_nSize + src.m_nSize);
CopyElements<TYPE>(m_pData + nOldSize, src.m_pData, src.m_nSize);
return nOldSize;
}
Kevin
|
|
|
|
|
Since CArray is a template class, you need to declare your array type as such.
You can either use something like this
CArray<CArrayMembersClass, CArrayMembersClass&>
or to shorten things up, use typedef to create an alias for the template class:
typedef CArray<CArrayMembersClass, CArrayMembersClass&> CArrayMembersClassArray;
and use "CArrayMembersClassArray" as a variable type.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
i tried
FindDF(CString file , CArray < CString, CString& > FArray)
and when i press OK nothing happends (pressed it many times)
|
|
|
|
|
I'm sorry...what?
What do you mean you "press ok"? Runtime? Design time?
I'm lost
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
hehehe sorry i let you alone inside forest
Ok here i am to rescue u !
i use Microsoft Visual studio C++ 6.0 enviroment
i press right click on the Class and press Add member function
on the window it pop up i time
Type: double
Function declaration : Find(CString file , ....) and i have to press OK or cancel
|
|
|
|
|
Ohhh ok
I've never used the add function wizard but I just tried it on VS 2003 .NET.
I chose "Add/Add function.." for a class.
Selected a return type
typed a function name
for the parameter type, I typed "CArray<int, int&> &"
parameter name I typed MyIntArray
clicked the Add button to add the parameter
clicked Finish and the function was added to my class
I'm not sure how different that is from VC 6 (I bet David Crow knows )
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
double CAnaktisiDlg::FindDF(CString file , CArray < CString, CString& > &FArray)
is what i create (indetifier CArray error)
double CAnaktisiDlg::FindDF(CString file , CArray < CString, CString& > FArray)
same :/
according to you it had to be working fine
|
|
|
|
|
Works for me but I'm on a different VS version.
I also have included afxtempl.h in my projects, although I'm not sure if the wizard uses that...
You can always add the function by hand
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi, I cann't take my own IP address on Windows Server 2003.
This is the code i'm using, it works fine in Windows 2000 (Professional and Server) and Windows XP, but DOESN'T WORK IN Windows Server 2003.
I'm getting crazy, Why it doesn't work only in Windows 2003?
int iSockErr = 0;
HANDLE hnd = 0;
WORD wVersionRequested = MAKEWORD(2, 2);
WSADATA wsaData;
try
{
if ((iSockErr = WSAStartup(wVersionRequested, &wsaData)) != 0) { throw 1; }
DWORD dw;
GUID guid = SVCID_HOSTNAME;
struct AUX{
WSAQUERYSET qsRestrictions;
BYTE byte[500];
}aux;
memset(&aux.qsRestrictions, 0, sizeof(WSAQUERYSET));
aux.qsRestrictions.dwSize = sizeof(WSAQUERYSET);
aux.qsRestrictions.lpServiceClassId = &guid;
if (WSALookupServiceBegin(&aux.qsRestrictions, LUP_RETURN_ADDR, &hnd)) { throw 2; }
dw = sizeof(aux);
memset(&aux, 0, sizeof(aux));
aux.qsRestrictions.dwSize = sizeof(WSAQUERYSET);
while ( !WSALookupServiceNext(hnd, LUP_RETURN_ADDR, &dw, &aux.qsRestrictions) )
{
ptyIP->d0 = aux.qsRestrictions.lpcsaBuffer[0].RemoteAddr.lpSockaddr->sa_data[2];
ptyIP->d1 = aux.qsRestrictions.lpcsaBuffer[0].RemoteAddr.lpSockaddr->sa_data[3];
ptyIP->d2 = aux.qsRestrictions.lpcsaBuffer[0].RemoteAddr.lpSockaddr->sa_data[4];
ptyIP->d3 = aux.qsRestrictions.lpcsaBuffer[0].RemoteAddr.lpSockaddr->sa_data[5];
}
...
Thank you very much.
|
|
|
|
|
alejandrofuchs wrote: Why it doesn't work only in Windows 2003?
Why don't you tell us? What does WSAGetLastError() return?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks,
It returns 0, indicating there is no error, but no data is returned.
alejandrofuchs@yahoo.com
|
|
|
|
|
Thanks!
First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name.
Second (again i'm sorry), i responded wrong, the rigth answer is: WSAGetLastError() returns 10110, WSALookupServiceNext is returning 0 the second time it is called.
alejandrofuchs@yahoo.com
|
|
|
|
|
alejandrofuchs wrote: WSAGetLastError() returns 10110...
Which resolves to WSA_E_NO_MORE .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
alejandrofuchs wrote: First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name.
hmmm...split personality?
If you try getaddrinfo(), does that work on Server 2003?
Something like:
char szHostName[256];
if (0 == ::gethostname(szHostName, sizeof(szHostName)))
{
char* port = "80";
addrinfo aiHints;
addrinfo *aiList = NULL;
int retVal;
memset(&aiHints, 0, sizeof(aiHints));
aiHints.ai_family = AF_INET;
aiHints.ai_socktype = SOCK_STREAM;
aiHints.ai_protocol = IPPROTO_TCP;
if ((retVal = ::getaddrinfo(szHostName, port, &aiHints, &aiList)) == 0)
{
addrinfo *pAddrInfo = aiList;
while (pAddrInfo)
{
pAddrInfo = pAddrInfo->ai_next;
}
<code>::freeaddrinfo(aiList);
}
}
-- modified at 14:41 Friday 8th June, 2007
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Yes, this works. I will change my code.
I still have the doubt about why it doesn't work only on Windows 2003, but as this code works fine i prefer this new aproach.
Thank you to you all for your help!
PD. Only for curiosity , if somebody find out what's wrong on the original code under 2003, please write.
alejandrofuchs@yahoo.com
|
|
|
|
|
alejandrofuchs wrote: I still have the doubt about why it doesn't work only on Windows 2003
I couldn't find any reason it wouldn't work in the Platform SDK for Server 2003...it's a mystery
to me!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
p.s. Don't forget to call freeaddrinfo() - I left that out of the code sample.
Cheers
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
EDITED: I have since fixed the problem, instead of using "delete this" in ThreadPool::Release(), I now call "delete m_threadPool" from Main.cpp. Now, I don't know exactly why this works, but here's a possibility:
Link to discussion on RtlFreeHeap
I will cut down on the source code that's not required to shorten my post.
/////////////////////////////////////////////////////////
So far, I haven't done too too much work on this project, however, I do have a few problems already. One is that when running the program, I get heap corruption (Error Message: HEAP[Core.exe]: Invalid Address specified to RtlFreeHeap( 00340000, 00373798 )). The second is that CThreadLocalObject::GetData() will cause an access violation exception which is handled (probably within MFC), but it still worries me that I get this exception. I can't debug into it either, so it's likely something I'm doing that's causing a failure somewhere deep below. The code might be a bit long for most people to want to read. The source code is posted below. The line that actually fails is "delete this" in ThreadPool::Release(). On top of all this, if anyone has any design considerations that they might have to offer, I would be glad to hear them. This is the first time I've worked with any multithreading framework, so any tips to prevent future headaches are appreciated.
Thanks a lot to anyone that takes the time to read this through.
#include <afxwin.h>
#include <THInc.h>
class MainWindow : public CFrameWnd
{
public:
CButton start;
CButton end;
CEdit textbox;
ThreadPool* m_threadPool;
EventSource* m_source;
EventReceiver* m_receiver;
MainWindow()
{
Create(NULL, "MFC Window");
start.Create("Start", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,30), this, 1);
end.Create("End", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,40,100,60), this, 2);
textbox.Create(WS_VISIBLE|ES_READONLY|ES_LEFT|ES_MULTILINE|ES_AUTOVSCROLL, CRect(10,70,100,120), this, 3);
}
void ButtonStart();
void ButtonEnd();
void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
DECLARE_MESSAGE_MAP()
};
void MainWindow::ButtonStart()
{
m_threadPool = new ThreadPool();
m_source = new EventSource();
m_receiver = new EventReceiver(m_threadPool);
m_receiver->HookThreadPool(m_source);
}
void MainWindow::ButtonEnd()
{
if (m_threadPool)
{
m_receiver->ReleaseThreadPool(m_source);
m_threadPool->Release();
m_threadPool = 0;
}
}
void MainWindow::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar == VK_ESCAPE)
MessageBox("Escape button pressed");
}
BEGIN_MESSAGE_MAP(MainWindow, CFrameWnd)
ON_BN_CLICKED(1, MainWindow::ButtonStart)
ON_BN_CLICKED(2, MainWindow::ButtonEnd)
ON_WM_KEYDOWN()
END_MESSAGE_MAP()
class Application : public CWinApp
{
public:
BOOL InitInstance()
{
m_pMainWnd = new MainWindow();
m_pMainWnd->ShowWindow(SW_SHOW);
return TRUE;
}
};
Application theApp;
#include "ThreadPool.h"
HANDLE ThreadPool::m_threadHandles[3];
map<int, WorkUnit*> ThreadPool::m_workQueue;
bool ThreadPool::m_terminate = false;
ThreadPool::ThreadPool()
{
InitThreads();
}
ThreadPool::~ThreadPool()
{
}
void ThreadPool::SignalTermination()
{
HANDLE termMutex = CreateMutex(NULL, false, "TerminateThreadPool");
WaitForSingleObject(termMutex, INFINITE);
m_terminate = true;
ReleaseMutex(termMutex);
}
void ThreadPool::Release()
{
WaitForMultipleObjects(3, m_threadHandles, true, INFINITE);
delete this;
}
void ThreadPool::InitThreads()
{
unsigned int threadID[3];
for (int i = 0; i < 3; i++)
{
int* index = new int(i);
m_threadHandles[i] = (HANDLE)_beginthreadex(0, 0, &ThreadPool::BeginThread, index, 0, &threadID[i]);
}
}
unsigned int ThreadPool::BeginThread(void* pArgs)
{
HANDLE hWQMutex = CreateMutex(NULL, false, "WorkQueue");
HANDLE termMutex = CreateMutex(NULL, false, "TerminateThreadPool");
while (true)
{
WaitForSingleObject(hWQMutex, INFINITE);
int key = -1;
WorkUnit* value = 0;
if (m_workQueue.size() > 0)
{
map<int, WorkUnit*>::iterator iter;
for (iter = m_workQueue.begin(); iter != m_workQueue.end(); iter++)
{
value = (*iter).second;
if (value->GetState() == WorkState_Queued)
{
key = (*iter).first;
value = (*iter).second;
value->SetState(WorkState_Active);
}
else
continue;
}
}
ReleaseMutex(hWQMutex);
WaitForSingleObject(termMutex, INFINITE);
if (m_terminate)
break;
ReleaseMutex(termMutex);
if (key == -1)
Sleep(1000);
}
m_threadHandles[*((int*)pArgs)] = 0;
delete pArgs;
return 0;
}
-- modified at 13:06 Friday 8th June, 2007
|
|
|
|
|
Hello,
When I try to create a new project w/ Visual Studio .NET 2003
I now keep getting a a Message Box that says (something like)
A critical error occurred, Automation object could not be created.
Does anyone know what this means?
--thanks
|
|
|
|
|