|
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. <
|
|
|
|
|
thanks for information.
So what i use?Plz help me
|
|
|
|
|
This[^] is where i found that you should avoid using it, just to show you i didn't make that up. Otherwise, i don't know what else there is, i guess you should ask Microsoft (look around MSDN), or you could try using Oracle Database 10g client[^], i think it is an ODBC "interface" of somesort...
> 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. <
|
|
|
|
|
Your database's name is
Database name ?
in such a case, possibly you've to replace
MsmVc wrote: CString udata="use 'databasename'";
with
CString udata="use 'Database name'";
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]
|
|
|
|
|
i always use like this
CString udata="use 'Database name'";
But still i have problem same.
|
|
|
|
|
uhm,
I think: the USE keyword (in t-sql) follow by YourDBName (YourDBName without quote) like this
USE YourBDName
or
USE [YourBDName]
|
|
|
|
|
Thank
But i test both case there is no effect in out put.Still same problem here.
|
|
|
|
|
Did you put USE YourDBName query and select query in same connection session ?
WHEN and WHERE did you use SELECT DB_NAME() AS DataBaseName ?
|
|
|
|
|
See as in first post first i make connection then i use
CString tr="USE tes";
Qry1=spSQLServer->ExecuteWithResults((_bstr_t)tr);
this code.
After that i use
SELECT DB_NAME() AS DataBaseName
If i am wrong then pls help me
|
|
|
|