|
I'm not sure why you think you need to do this, but remember that Visual Studio will not let you use _asm in x64 builds.
|
|
|
|
|
There are several issues here:
a. As already mentioned there is no point in using inline assembler for a function call. Inline assembler is occasionally (but very rarely nowadays) used for efficiency or for doing some low-level hardware things. But even if you have to use assmebler for something you can move results to local variable(s) for passing to functions in normal C/C++ code.
b. You can't just do a "call" to an arbitrary memory location (as in your 1 and 2 examples). You have to use some sort of symbolic name so the linker can resolve the addres and the loader can adjust addresses when the program is run.
c. Your example 3 looks like it could work but I think you are pushing the parameters onto the stack in the wrong order.
d. Where does the code crash? I suspect in the call to WinExec but you can step through the code in the debugger to see exactly where it goes wrong. (Use Debug/Windows/Disassembly menu item to get the assembler code in the debugger.)
e. Check what registers you can use in an _asm {} block. I think eax is safe but you may have to save (ie push and later pop) others like ebp before using them.
Andrew Phillips
http://www.hexedit.com
andrew @ hexedit.com
|
|
|
|
|
I setup the mysql5.0 and sdk.
now I create a mfc dialog project, and use it in the Main Thread ,it's no problem.
but I create another thread, in the thread function I define a variables like this:
DWORD CTestDlg::ThreadFun(LPVOID lParam)
{
CTestDlg *pDlg = (CTestDlg *)lParam;
MYSQL mysql;
mysql_init(&mysql); // here is access violation.
Unhandled exception in Test.exe(MYSQLD.exe): 0xc0000005: Access Violation.
// if I use it in the main thread,is ok.
}
so how to use the mysql in the child thread ?
|
|
|
|
|
Syntax for mysql_init:
MYSQL *mysql_init(MYSQL *mysql)
Try this:
MYSQL *mysql;
if(mysql_init(mysql) == NULL)
{
}
Alternatively, you can pass the mysql object to the ThreadFun after initializing it in main thread.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
i know there is a API function names: InterlockedCompareExchange
i do not want to exchange, i just wana an atomic compare ?
thanks - -!
|
|
|
|
|
cl_gamer wrote: i do not want to exchange, i just wana an atomic compare
That does not make much sense to me. If your data items are volatile, comparing them and later on acting on the outcome would be unpredictable, as the compare result may become stale right away.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi to all,
I am unable to get the Cue Banner Text in the Edit control. Below is the code i had used.
case WM_INITDIALOG:
SendMessage(GetDlgItem(hwnd,IDC_USER), EM_SETCUEBANNER, 0, (LPARAM)TEXT("Username"));
break;
Is something extra is required to achieve the cue banner in edit control.
Regards,
Vishal
|
|
|
|
|
The text for your "Username" must be wide character
case WM_INITDIALOG:
SendMessage(GetDlgItem(hwnd,IDC_USER), EM_SETCUEBANNER, 0, (LPARAM)L"Username");
break;
Other than that, it's supported on WinXP and later - and I believe you need to have WINVER set to 0501 or higher - at least you used to need that.
If your project is Unicode, then the TEXT macro will do, but if it's not Unicode, you must use the L prefix to create a wide character string.
Hope this helps
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Everything is ok but still can't get the Cue Banner Text in Edit control.
Regards,
Vishal
|
|
|
|
|
What you've given is correct.
You're probably not seeing the banner because the edit control has the focus.
You can give the value of 1 for wParam to show the banner even if the control has focus.
SendMessage(GetDlgItem(hwnd,IDC_USER), EM_SETCUEBANNER, 1, (LPARAM)TEXT("Username"));
|
|
|
|
|
You're probably right that the control has focus, thus preventing the cue banner from showing, however the OP must still insure that it's a Unicode build if TEXT is used. If the build is non-Unicode, the L prefix is required.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
In my MFC app, I needed to sleep (delay the thread) for 3 seconds. But when I added sleep in BtnClick afx function, it just didn't work. I did a work around be using 3 seconds Timmer. But How to avoid such situations in future???
Thanks for reply in advance
--
CHEERS!!!!
|
|
|
|
|
How did you conclude that the sleep function does not work?
Did you see any frozen UI for 3 seconds?
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
I am creating a Custom Media Player using Windows Media Player COM objects. When I play the mp3, it takes near about 3 sec to load the files(and necessary dlls). Before that, the duration of the mp3 is not reflected in the properties. Yes there was a frozen UI. But rest of the thread continued and I was unable to record the duration.
Thanks for replying
|
|
|
|
|
Are you using another thread to read/load the necessary files or the dll's or you are doing it in the main thread?
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
I am loading it in the main thread itself...
|
|
|
|
|
Then obviously your code for loading the dll's etc will not run during the freeze/sleep as the main thread is sleeping. You should load all dll's in a separate thread and once you are sure that they are loaded, notify the main thread to resume. May be you could have a better idea as well.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
great feedback for OP
|
|
|
|
|
UI frozen=Sleep worked... like it was suggested, create a loading thread and have that thread message back to the original thread when he's done. Using Sleep() in this manner is not acceptable, you're freezing the user interface on purpose, many do it on accident, but on purpose!?
|
|
|
|
|
So does that means using Sleep() (in main thread) in mfc in condemned??? I never realized that. I think a lighter way was what I did (activated a timer and went to sleep there). Thread is also a good option. Thanks for the reply.
|
|
|
|
|
It's condemned to use Sleep()(for this length of time) in UI thread(its common for people to separate the UI from the rest of the code).
|
|
|
|
|
How do i find last created file in a specified directory?
|
|
|
|
|
Enumerate the files using FindFirstFile & FindNextFile. Using WIN32_FIND_DATA compare the properties and time stamps or whatever is required. You will need to compare the file creation times using an algorithm
FILETIME ftCreationTime; will be of interest in your case.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
|
Hi ,
I have used the following code to send Message to a vb window,
While using this code in win32 application i can able to find the child window and no problem with my code,
But while using this in an mfc application cant able to find the child window and
it is always null.
Please help to solve my problem,
Thanks in advance.
HWND FormhWnd;
long uClickYes;
long Res ;
long lngresult;
UINT sendtxtmsg;
sendtxtmsg = RegisterWindowMessage("SEND.TEXT.MSG");
LPCSTR strCaption ;
LPCSTR strClass ;
LPCSTR TextBoxCaption ;
strCaption = "WINDOWNAME";
strClass = "ThunderRT6TextBox";
TextBoxCaption = "";
FormhWnd = ::FindWindow(NULL, "WINDOWNAME");
CString txtval;
txtval.Format("%d",sendtxtmsg);
if (FormhWnd != NULL)
{
HWND findchild;
AfxMessageBox("FormhWnd not null");
findchild = FindWindowEx(FormhWnd, NULL, strClass, NULL);
if (findchild != NULL)
{
AfxMessageBox("findchild not null");
FILE *fp;
fp=fopen("sendmsg.txt","w");
fputs("joined Channel..",fp);
fclose(fp);
Res = ::SendMessage(findchild, sendtxtmsg, 1,0);
}
else
{
AfxMessageBox("findchild null");
}
else
{
AfxMessageBox ("PARENT WINDOW NULL");
}
nick
|
|
|
|