|
don't do UI in the worker thread; ask the main application thread to do it by sending messages and using event and things like that to keep everything synchronized.
read :
http://www.flounder.com/workerthreads.htm[^]
and everything thread related on that site.
This signature was proudly tested on animals.
|
|
|
|
|
Is the second launch waiting for the first to be ended?
If not... you may have problems with DoModal () multiple calls. Would not be better to use ModalLess dialogs?
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Shailesh H wrote: line 2:dlg.SetTitle(strDialogTitle);//Set the dialog Title
Is strDialogTitle of type CString? If then is it shared across threads?
-Suhredayan
|
|
|
|
|
Hi friends,
I am having just one month of experience in network programming. I want to sniff TCP packets using Winsock. I could right the code for that as below. It worked on XP 32 bit but not on Vista Home 32 bit machine.
SOCKET sniffSocket;
if((sniffSocket= socket(AF_INET, SOCK_RAW, IPPROTO_IP))==SOCKET_ERROR)
{
return 0;
}
struct sockaddr_in src;
memset(&src, 0, sizeof(src));
src.sin_addr.S_un.S_addr = inet_addr (pAdapterInfo->IpAddressList.IpAddress.String);
src.sin_family = AF_INET;
src.sin_port = 0;
if (bind(sniffSocket,(struct sockaddr *)&src, sizeof(src)) == SOCKET_ERROR)
{
return 0;
}
int j=1;
if (WSAIoctl(sniffSocket, SIO_RCVALL, &j, sizeof(j), 0, 0, &in, 0, 0) == SOCKET_ERROR)
{
return 0;
}
char *pkt_data = (char *)malloc(65536);
int res;
do
{
res = recvfrom(sniffSocket, pkt_data, 65536, 0, 0, 0);
...
...
}
while (res > 0);
...
...
The above code is working fine on XP. I could sniff TCP/IP packets (in pkt_data variable) this way. But when I run the same code on Vista, I am able to trace only UDP/IP packets. Can anybody tell me please why is it not working on Vista? I mean what is the problem with my code that I cannot sniff TCP/IP packets?
My second query: A system can have multiple adapters/devices. When we type a web-site address on a browser, we don't tell which adapter to connect to. Browser automatically opens adapter that is connected to internet. How it does that? I mean how can I detect which adapter is being used for internet connection? Is there any Winsock API for the that?
Thanks in Advance
Regards
Aseem
modified on Wednesday, December 23, 2009 1:30 AM
|
|
|
|
|
Please use the code block to post code snippets (as it stands your code is unreadable).
Please elaborate, i.e. what does it mean 'it doesn't work on Vista'? Are you getting errors? Are you getting a misbehaviour (detail it)?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi Pallini,
I am sorry I did not write the code snippet right way. I have corrected it now. Please have a look over it.
As I said my code is working fine on XP. In my application I need to make a dump of TCP/IP packets. I could do so on XP. But when I run the same code on Vista, I get only UDP/IP packets (in variable pkt_data). I do not know why I am not getting TCP/IP packets (in variable pkt_data). Apart from it, I am not getting any error or misbehavior.
My second query is that is there any way by which I can know through which adapter the system is connected to internet so that I can sniff TCP/IP packets from that adapter only.
Thanks and Regards
Aseem
|
|
|
|
|
I developed a windows service which was written in VC++ (6.0) earlier and was directly migrated to VS2008 (C++).
The migrated service works fine in Windows 2000 Server but gives access violation exceptions when started in Windows Server 2003 and Windows XP system.
Is there some thing different in Windows 2003 server with respect to windows 2000?
Do I need to make some settings for this to make work?
With Regards,
Abraham Jose
|
|
|
|
|
Did you run it in the debugger to find out what the exceptions are?
|
|
|
|
|
After converting project from VC6.0 to VS2008,while running application it shows the following error
Unhandled exception at 0x787ac40c (mfc90d.dll) in CS3OperatorStation.exe: 0xC0000005: Access violation reading location 0x00000020.
When i debug it,i got this error in this particular line
void tSendActiveData()
{
while(1)
{
AfxGetMainWnd()->SendMessage(WM_COMMAND,ID_SENDACTIVEDATA,NULL); Sleep(500);
}
}
tSendActiveData is a thread.
I want to invoke this fucntion in this thread.thts why im using it.
Its working fine in VC6.0 version.
Anu
|
|
|
|
|
You shouldn't do this. You should post a message to the main thread, using global namespace's PostMessage [^] with target the main window handle (you may pass it to the worker thread).
See this article [^] on how to use worker threads (read carefully the "Worker Threads and the GUI IV: AfxGetMainWnd" section).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Please check the return value of AfxGetMainWnd(). This function is supposed to return the main windows associated with the thread. As your thread does not have a window, the return value might be zero.
|
|
|
|
|
Me think that AfxGetMainWnd() will return the window of the thread, not of the main application.
Pass a pointer of your main application window to your thread.
Max.
This signature was proudly tested on animals.
|
|
|
|
|
|
Hint: the thread function has a parameter...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Now im converting VC+.0 project in to VS2008 version.
It shows error on line
RFile.open(FName,ios::app,filebuf::sh_read);
as sh_read: Undeclared identifier
I included #include<fstream>,Using Namespace std;
But no use.It contniously show this error.
i declared RFile in header file as
class StreamOut : public ofstream
{
public:
StreamOut()
{
}
};
StreamOut RFile;
Im using RFile to Write also as
RFile.write(PageNo,2);
.
.
But it shows error on sh-read.
Anyother way to do this?
Anu
|
|
|
|
|
Did you forget to mention the namespace std?
|
|
|
|
|
Yes, i included.
Now i change the fucntion as follow
RFile.open(FName,ios::app);
Now i doenot show error.I dont know its correct or not.
Anu
|
|
|
|
|
error C2487: 'CSingleton<T>::ms_pSingleton' : member of dll interface class may not be declared with dll interface
When I try to compile the below code in VS2008 above is the error. I am not sure hw to fix this, as the class is not exported (i am getting this error even when i try to export the member alone).
So please suggest me a better solution.
template <typename T>
class CSingleton
{
private:
ExportSlotCoreLib static T* ms_pSingleton;
CSingleton(const CSingleton&);
protected:
CSingleton() {
//assert(ms_pSingleton == NULL);
int offset = (char*)(T*)1 - (char*)(CSingleton <T>*)(T*)1;
ms_pSingleton = reinterpret_cast<T*>(reinterpret_cast<char*>(this) + offset);
}
~CSingleton() {
//assert(ms_pSingleton != NULL);
ms_pSingleton = NULL;
}
public:
static T& GetSingleton() {
return (T&)*ms_pSingleton;
}
static T* GetSingletonPtr() {
return ms_pSingleton;
}
};
Thanks,
Nandu
|
|
|
|
|
Can you remove ExportSlotCoreLib from pSingleton declaration and try?
|
|
|
|
|
Hi All
USE database command is not working for me.I was asking same question in last week but still i have no solution then i ask one more time.Plz help me
connection code is here
CString str1="",str2="",str3="";
HRESULT hr;
if SUCCEEDED(hr = CoInitialize(NULL))
{
try
{
if (SUCCEEDED(spSQLServer.CreateInstance(__uuidof(SQLServer2))))
{
try
{
HOST=(_bstr_t)m_MHOST;
if(rad1.GetCheck())
{
spSQLServer->LoginSecure = TRUE;
spSQLServer->Connect((_bstr_t)m_MHOST);
}
else
{
spSQLServer->LoginSecure = FALSE;
spSQLServer->Connect((_bstr_t)m_MHOST,(_bstr_t)m_MUSR,(_bstr_t)m_MPWD);
}
}
catch(_com_error pCE)
{
str2.Format(_T("%s"),
MessageBox(str2,"Message");
return TRUE;
}
}
else
{
str3.Format(_T("Unable to create the SQL Server object.\n"));
}
}
catch(_com_error pCE)
{
str2.Format(_T("\n%s Error: %ld\r\n%s\r\n%s\r\n"),
(TCHAR*)pCE.Source(),
pCE.Error(),
(TCHAR*)pCE.Description(),
(TCHAR*)pCE.ErrorMessage());
}
}
else
{
str2.Format(_T("Call to CoInitialize failed.\n"));
}
Use database command code is here
QueryResultsPtr Qry;
_SQLServer2Ptr spSQLServer;
CString udata="use 'databasename'";
Qry=spSQLServer->ExecuteWithResults((_bstr_t)udata,(LONG)udata.GetLength());
Select command is running fine like this
CString sel="select * from 'Database name'.dbo.'Table Name'"
Qry=spSQLServer->ExecuteWithResults((_bstr_t)sel,(LONG)sel.GetLength());
Can any one help me why
USE 'Database name' not working.
Plz help me
|
|
|
|
|
MsmVc wrote: USE database command is not working for me.
-explain, does it give an error, does it simply not do what is expected (e.g: it completes successfully but does not seem to make any change), how do you know it fails?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
it completes successfully but does not seem to make any change.
After use database command then i check through this command.
SELECT DB_NAME() AS DataBaseName
it's always show "Master" database name.
|
|
|
|
|
Let's experiment, try this:
CString udata="use \"databasename\"";
Qry=spSQLServer->ExecuteWithResults((_bstr_t)udata,(LONG)udata.GetLength());
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
thanks ,i use code which is given by you.But i got error
Microsoft SQL-DMO (ODBC SQLState: 42000) Error: -2147221402 [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'databasename'. Invalid STDGMEDIUM structure
|
|
|
|
|
How about CString udata="use databasename"; ? Btw do you know that -according to msdn- Microsoft recommends not using sql-dmo in newer products because it will be removed by them?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|