|
Thanks for the reply. Your explanation sounds plausible, although there doesn't seem like a way for me to confirm this. I am pretty sure this has nothing to do with multiprocessors and QueryPerformanceCounter() as there is a lot of info that suggests the use of /pmtimer in the C:/boot.ini file to fix incorrect timing results. I'm also unsure as to how well using SetThreadAffinityMask() works for timing, as I don't believe it provides any guarantees, only a suggestion. In another application that I was developing, using SetThreadAffinityMask() before calling QPC still gave me some timing results that were off, on 32-bit Windows XP (64-bit Windows XP, however, didn't have any such issues).
|
|
|
|
|
I want to export some functions from an executeable file. How to do it.....
In exe export function like below, and add .def file add foo to exports.
<br />
__declspec(dllexport) int __stdcall foo(int i, int j)<br />
{<br />
return i+j;<br />
}<br />
In another exe file invoke function like this:
<br />
typedef int (__stdcall *FOO)(int, int);<br />
<br />
HMODULE hModule = LoadLibrary("C:\\Export.exe");<br />
if (hModule != NULL)<br />
{<br />
FOO pFun = (FOO)GetProcAddress(hModule, "foo");<br />
if (pFun != NULL)<br />
{<br />
TRACE("%d\n", pFun(1, 3));<br />
}<br />
}<br />
I Got an "Access Violation" error.
Hongjun Ge
|
|
|
|
|
you can't.
(not safely, anyway)
|
|
|
|
|
But he has an export table, right?
AFAIK, it is perfectly possible, albeit not very common. From MSDN[^]:
LoadLibraryEx Function
Maps the specified executable module into the address space of the calling process. The executable module can be a .dll or an .exe file.
|
|
|
|
|
hmmm...
perhaps i was mistaken.
|
|
|
|
|
Nemanja Trifunovic wrote: LoadLibraryEx Function
But the OP is still using LoadLibrary and not LoadLibraryEx
|
|
|
|
|
|
You may want to know the difference in accessing a function from a .exe and a .dll. Dlls run in the same process space where your calling application runs. So you can call functions just like that!
| |
| Dll |
| |
^
|
|
v
|calling|
| EXE |
| |
But to call a function in an exe, you cannot access it straight unless you have a function like LoadLibraryEx because it runs in a different address space. You need to "marshal" the calls if in different spaces. But as pointed up Nemanja, LoadLibrary should be able to do that.
| | Marshal/LLEx |calling|
|exe|<------------>| EXE |
| | | |
|
|
|
|
|
You mentioned on dllexport with declspec.
If you are exporting functions from Exe, I dont think dllexport will work. As this is only just for DLLs not for EXE. I dont know for exporting functions from exe what convention is used?
|
|
|
|
|
glitteringsound wrote: I dont know for exporting functions from exe what convention is used?
You can always do something like this:
<br />
#define EXEEXPORT __declspec(dllexport)<br />
<br />
void EXEEXPORT MyExportFunction() {<br />
<br />
}<br />
<br />
|
|
|
|
|
i would like to create a toolbar which is docked to the left side of the SDI window but which has two column instead of one which is the default. What i already know is:
1. Derive a class from toolbar
2. Include a handler for WM_SIZEPARENT, which is MFC's private message.
3. Overwrite the virtual functions CalcDyanamicLayout and CalcFixedLayout in my derived class.
4. Write code in CalcDynamicLayout and CalcFixedlayout to set the flags of each button in the toolbar.
5. Use my derived Toolbar to replece the original toolbar.
I need help in 3 and 4 especially 4. I am also getting some kind of error when i close my application. Anyone who can help me out would be great. If you have better idea, please advise so.
Mark
|
|
|
|
|
You shouldn't need step 2.
I personally use a CControlBar with CToolbars embedded (members of the
control bar).
Here's 3 reasons why...
In the CControlBar class Calc____Layout() override(s) I can return a CSize
that has the appropriate dimensions to fill a side of the parent frame window.
In the CControlBar class Calc____Layout() override(s) I can resize the embedded
toolbar(s) to force it to wrap the rows/columns of buttons into multiple rows or
columns (depending on orientation).
With CControlBa, it's easy to mix toolbars and any other windows/controls and wrap them
all nicely in one bar docked to the frame.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I got your idea. But i am not sure if i can not do it the way i am doing it. That is derive my class directly from CToolBar. I think you are saying that derive my class from CControlBar, which has CMyToolBar class embedded in it which is more flexible.
I would need CControlBar the way you described it as an option bar in my application which will be horizonal. My vertical bar needs not to be moved and will be fixed. Depening on which button you press in ver bar, the right option bar should show. It is more like adobe photoshop type application that i am trying to develop.
You said i do not need step 2. That is using WM_SIZEPARENT. Is that what you really meant. Please explain a little. And thanks for the help.
Mark
|
|
|
|
|
Hi all, im trying to make an application that requires me to use the API WinMain() and it just so happens i need to use argv and argc. Problem is that WinMain takes 4 arguments in it and doesnt have room for argc/argv[]. So i looked up the issue and as it turns out MS didnt allow the usage for whatever reason (which really isnt important to me because i need to make it work.) So i figured if i cant put it in the calling function then make it apart of a if statement. So this is what i did.
<br />
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){<br />
string file2="C:\\Debug\\test.exe";<br />
<br />
if(__argv[0] == file2){<br />
ofstream file;<br />
file.open("test.txt");<br />
file << "Sponcer brought to you by - Subway! Eat Fresh! :) " << endl;<br />
file.close();<br />
system(buffer);<br />
exit(1);<br />
}<br />
else{<br />
Sleep(1000);<br />
exit(1);<br />
}<br />
return 0;<br />
}<br />
And it works. But my problem is that i dont want to have to specify the name of the program and file path etc etc. Thats what argv[0] is for. So what im trying to do is this....
Use argv within the WinMain function so that i can print out file/path info. That way i can work my way around other problems. Thanx in advance!
|
|
|
|
|
I don't quite understand your question, but have you taken a look at WinMain() 's third parameter, lpCmdLine ?
"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
|
|
|
|
|
Im trying to get the current file name from argv using WinMain(). But since i cant put argv[] or argc in the function arguments, i have to use another method. Thats what im saying
|
|
|
|
|
dellthinker wrote: Im trying to get the current file name from...WinMain().
So how about GetModuleFileName() ?
dellthinker wrote: But since i cant put argv[] or argc in the function arguments, i have to use another method.
And that way is fine. There's nothing wrong with using __argv[0] .
"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
|
|
|
|
|
You need to use GetCommandLine and CommandLineToArgvW like
#include <windows.h><br />
#include <stdio.h><br />
#include <shellapi.h><br />
<br />
int __cdecl main()<br />
{<br />
LPWSTR *szArglist;<br />
int nArgs;<br />
int i;<br />
<br />
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);<br />
if( NULL == szArglist )<br />
{<br />
wprintf(L"CommandLineToArgvW failed\n");<br />
return 0;<br />
}<br />
else for( i=0; i<nArgs; i++) printf("%d: %ws\n", i, szArglist[i]);<br />
<br />
<br />
LocalFree(szArglist);<br />
<br />
return(1);<br />
}
|
|
|
|
|
in the C++,there are some ashen character,what is that mean especially?
|
|
|
|
|
youbo wrote: ashen
i've never seen that word used in a programming context.
|
|
|
|
|
youbo wrote: ...ashen character...
Covered in ash?
"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
|
|
|
|
|
in the C++,the key is blue,the generic character is black,but there are some characters is ashen,like endif at somewhere.don't you have seen?
|
|
|
|
|
I don't have my IDE configured in such a fashion.
"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
|
|
|
|
|
Are you using Visual Studio?
Russell
|
|
|
|
|
I am using the RegQueryValueEx() Function to fethch the value from the reggistry I set previously.
But getting porblem. It fetches only first charcter only.It Show the Corrent size of the Value but Fail to Fetch the Whole String.Previously I was using the RegQueryValue() and It is working Fine . But I need to use RegQueryValueEx() as I have to fetch Other valued in addition with default.
The Code I am using is as follow.
RegOpenKey(HKEY_CURRENT_USER,L"Software\\PersonalMenu",&hKey);<br />
Code= RegQueryValueEx(hKey,L"JAVA",0,&Type,NULL,&size);<br />
BYTE *Data = new BYTE[size];<br />
Code= RegQueryValueEx(hKey,L"JAVA",0,&Type,(BYTE *)Data,&size); <br />
I dont know what is the problem with it. If it is showing the Correct size of the Value don't it also show the Value.
|
|
|
|