|
Hello,
Hope somebody can help me.
I'm using VC++ 2003 and i want to make a connection to MySQL database in my MFC program.
cx_jin comment this:
#include "mysql.h"
#include "winsock.h"
#pragma comment(lib,"libmySQL.lib")
MYSQL mysql;
mysql_init (&mysql);
if(!mysql_real_connect(&mysql,"localhost","root",NULL,"mydb",3306,NULL,0))
{
AfxMessageBox("database connection error");
return FALSE;
}
A link or a thread will do.
Your comment will be a big help.
Thanks.
|
|
|
|
|
TooShy2Talk wrote: I'm using VC++ 2003 and i want to make a connection to MySQL database in my MFC program.
Ok, so what is it about your code snippet that is not working?
TooShy2Talk wrote: Your comment will be a big help.
As would your description of the problem.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for the time.
Well, I just want to seek help on how can I make the source code above work.
or you have other way to connect to MySQL.
I run the code but I don't have "mysql.h" and i think the lib.
Where can i get these files? Are they downloadable?
I have found other code but I don't know the provider for MySQL.
Please reply.
Thanks
|
|
|
|
|
TooShy2Talk wrote: I run the code but I don't have "mysql.h" and i think the lib.
Exactly how are you running the code in the absence of a necessary .h and .lib file? Sans those, you are not even compiling the code, let alone running it.
To narrow down the problem a bit, try:
MYSQL mysql;
if (mysql_init(&mysql) != NULL)
{
if (! mysql_real_connect(&mysql, "localhost", "root", NULL, "mydb", 3306, NULL, 0))
{
CString str;
str.Format("mysql_real_connect() failed. Error: %s", mysql_error(&mysql));
AfxMessageBox(str);
return FALSE;
}
}
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The following bit of code is from the Atmel AtUsbHid example. Can someone please explain the line DYNCALL(writeData)((UCHAR *)"12") which i believe is part of a DLL, maybe....
I know the code turns on and off a LED but i want to know how the code works....
void CUsbHidDemoCodeDlg::OnLed2()
{
if(Led2 == false) {
Led2 = true;
m_Led2.SetWindowText(_T("LED 2 ON"));
DYNCALL(writeData)((UCHAR *)"12");
}
else {
Led2 = false;
m_Led2.SetWindowText(_T("LED 2 OFF"));
DYNCALL(writeData)((UCHAR *)"02");
}
}
Thanks
Don
|
|
|
|
|
DYNCALL will be a macro defined elsewhere. You need to find the definition to determine what these lines in your sample expand to. It will probably be some kind of function call like
<br />
DYNCALL(writeData)((UCHAR*)"12")); => SomeType result = writeData((UCHAR*)"12"));<br />
Without the macro definition there's no way for me to tell exactly. I often use a similar macro arrangement to call DLL functions and it can expand into quite a lot of code including, loading the Dll, looking up the function, caching the function pointer and making the call in try{}catch{} block so that a bad or missing DLL won't kill your application.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Is it possible to make VC6 use both cores when compiling? I've got HT on but CL.EXE only utilises one core.
|
|
|
|
|
I think the general answer is no. You'd have to run 2 copies of CL.EXE working on different parts of the project and possibly even then you might need to fiddle with processor affinity to stop them fighting over 1 core. Make the move to VS 2005 before it too becomes obselete, the back end really is much better.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
That was what I feared. The problem with moving to VS2005 is that I have a 250k-loc project that I cannot spend the time to convert, so I'm kinda stuck with it.
Oh well, better put in for a new machine...
|
|
|
|
|
A new machine is always good Even with a very large project though conversion may still be worth the time and effort if the original source is good. We ported our little system of 50 COM Dlls using MFC and ATL and MSVCRT in less than 4 person/weeks including moving the CRT string calls over to the secure versions to get rid of the warnings. We've only had 2 very minor bugs as a result in the following 18 months. I was surprised how easy it turned out to be but I had been very fortunate to inherit a great source base.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Steve_Harris wrote: I've got HT...
Is this now considered a dual-core CPU.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
*shrug* dunno. The CL.EXE compilation thread only runs on half of it so it looks very much like one.
|
|
|
|
|
My CAsyncSocket::Connect() call returns 0 and the GetLastError returns 10035 (WASEWOULDBLOCK). I understood it all so far that with this error code my OnConnect() will be called, when the Connect() finishes.
The problem I have now, that it never calls back; but when I have that:
<br />
if( (Client.Connect(cServerIP, Port) == 0) && (Client.GetLastError() == 10035) ) <br />
{<br />
AfxMessageBox("");<br />
}<br />
The callback comes immediately.
I programmed kind of a heartbeat function, which works in the way that my Server waits 2secs after receiving the last life-sign and then sends an Echo Request and waits for 500msecs for an answer and my Client sends an Echo Ackknowloedge back. With the MessageBox this works fine, but only until the OK Button of the MB.
I tried to find answers in the Net and in the MSDN, but I couldn't.
Could you please help me?
What happens due to that MB?
How can I surround the MessageBox?
How can I make Connect() return !0?
|
|
|
|
|
Check if MFC Sockects still use a hidden Window to make them work so that you must have a mesage loop active (e.g. a message box or dialog or your own main window) for them to work. I thought this changed after MFC 4.2 but I've not used the more recent versions except on WinCE where they're different anyway.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Thank you
I am a Step further now, that I know I have to have my Main Dlg's Message loop, I tried it with DoModal(), just for testing, and I got my OnConnect(), but I got an assertion, too, because my Dialog is non Modal.
Is there a way making the Dlg Message loop run?
As you might see in my answer I am not gone far from a bloody beginner
|
|
|
|
|
I'm going to assume you're doing this all on one thread...
As Matthew mentioned, MFC uses a hidden window to handle asynchronous socket
messages.
If you're going to use sockets asynchronously on one thread, then you need to
make sure you do your socket operations in the "callbacks" and return immediately
so the message loop can continue running.
If you go into a modal loop somewhere (like if you use the Win32 ::MessageBox()
API) then your sockets will stop responding.
If you're not already doing so, you may want to try AfxMessageBox() instead of
::MessageBox(). MFC simulates modal dialogs by using modeless dialogs so maybe
your socket messages will still get dispatched.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
No I am doing my connect attempt in a new thread, and found out that I can't pass Sockets between threads and have to use the Socket Handles; so sorry for sending you on the wrong way
|
|
|
|
|
Hi guys, I'm back. Don't think that I'm going be a harassment person to you all
My question is this. In my application I've create a button which is used for file browsing. Code it and work it fine. What I want to do now is, adding an image to that button. A small image which user can identify that this button is for browsing.
Any suggestions for me.
I appreciate your help all the time...
Eranga
|
|
|
|
|
CBitmapButton
or an Static control with an icon, not IN the button, BY the button
or an easy caption with "Search file..."
-- modified at 4:22 Wednesday 7th November, 2007
Greetings.
--------
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
|
|
|
|
|
|
See these codes and in the end you must release memory with calling DeleteObject.
//////For button///////
HBITMAP hbitmap;
hbitmap=(HBITMAP)LoadImage(NULL,_T("e:\\1234.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
m_Button.ModifyStyle(0,BS_BITMAP);
m_Button.SetBitmap(hbitmap);
//////////For Static control
HBITMAP hbitmap;
hbitmap=(HBITMAP)LoadImage(NULL,_T("e:\\1234.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
m_Static.ModifyStyle(0,SS_BITMAP|SS_NOTIFY);
m_Static.SetBitmap(hbitmap);
also you can use of CBitmapButton class.
|
|
|
|
|
Eranga Thennakoon wrote: Any suggestions for me.
Try this.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks pal.
I appreciate your help all the time...
Eranga
|
|
|
|
|
The function I wanted is when a subitem contains some text, I use some textcolor to show the subitem.
my code are:
first map the message
BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
END_MESSAGE_MAP()
void CMyListCtrl::OnCustomDraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPLVNMCUSTOMDRAW lplvcd = (LPLVNMCUSTOMDRAW)pNMHDR;
int iItem = lplvcd->nmcd.dwItemSpec;
int iSubItem = lplvcd->iSubItem;
switch (lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
return;
case CDDS_ITEMPREPAINT:
{
*pResult = CDRF_NOTIFYSUBITEMDRAW;
return;
}
case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
{
CString strSubItem;
strSubItem = GetItemText(iItem, iSubItem);
if (strSubItem.Find(_T("loop")) != -1)
{
lplvcd->clrText = RGB(200, 200, 0);
}
<big>
else
lplvcd->clrText = ::GetSysColor(some nornal color);
</big>
*pResult = CDRF_DODEFAULT;
return;
}
}
}
-- modified at 21:14 Wednesday 7th November, 2007
|
|
|
|
|