|
Hi,
Does anyone know how to install a callback function between two applications?
I guess that this shouldn't be too difficult (basically you just have to transmit a callback address), but I'm worring about the operating system shifting my applications in the memory. In this case the address isn't correct anymore, is that right? Is there an easy way of doing this?
Thanks for your help
|
|
|
|
|
You do not need to worry about the OS moving your application around in memory because you only deal with a virtual address, and that will not change, however, the virtual address that you receive in process A will not be valid in process B. This makes calling a callback function not as simple as you would think.
You will need to do some form of inter-process Communication (IPC).
There are a number of ways that you can do this including, I listed these in an order of difficulty from easiest to most difficult:
Send a message to the second process and the message handler will call the function for you.
Create a COM object.
Use a memory mapped file to communicate between the two applications, monitor the data that is written in to the file and take appropriate actions.
Use a Remote Procedure Call (RPC). This is a networking mechanism that will scale to applications located on other machines, probably overkill in your case.
I would suggest the message mechanism. This is the same mechanism that you would probably use in a multi-threaded application.
Kilowatt
|
|
|
|
|
Thanks for your answer
Just another question: if I solve the problem by using messages between the two processes, this means I use messages to tell the second application the address of the callback? Or use the messages instead of the callback?
My concret problem: I have an application which renders a 3D world. The 3D world is refreshed continuously everytime the message queue is empty.
I have a second application which can make modification to some objects in the 3D world through a dll with a shared data segment. The modifications are not directly reported on the 3D world, because all modifications have to be done just before the rendering. The modifications are stored in the shared data segment until a "redraw"-command is executed. I think everything would be easier if I could install a callback (in which I can update the data) which is called just before the rendering.
Can't I somehow deduce the absolute adress of a callback function given the virtual adress?
|
|
|
|
|
The reason why you cannot do this is because you cannot access the memory in the second process. If you call the callback function in process 1 with an address of a function that you determined from process 2, you will be accessing the data this is at the memory location in process 1. This will most likely result in a memory access error.
WIN32 allows each application to have their own completely independent address space. This is why you cannot match the memory from one process to another. Even if you could find the absolute or physical address of the function call to the redraw command in your second app, the OS would change this address out from under you. That is why it is nice to work with virtual memory addresses, the memory moving becomes transparent to the application programmer. This would not be an issue in WIN16 because all applications shared the same address space.
The reason why you can access the shared data segment of the DLL and modify the memory is because windows maps the shared data segment of the DLL into a memory mapped file.
Since you already have shared data, you may just want to set an update bit that the Rendering app can monitor in its idle state and determine if it is time to update.
kilowatt
|
|
|
|
|
alright;
now i need to read a sequence of numbers from a file and then store them in a linked list.
thanks
|
|
|
|
|
Hi.
I am experience recursive random number. It seems that only happens when rand() is in a loop.
For example:
--------------------------------------
srand(time(0));
int tempNUM = 0;
for (int i = 0; i < 1000; ++i)
{
tempNUM = 1 + rand() %9999999;
cout << tempNUM + 1;
}
--------------------------------------
In a program I am working on with a similar code to the one above, the program generates duplicates random numbers. It seems I have to *wait* one second clock until it generates a something new. Does that have something to do with time(0)?
I would like something that can generate a completely random number almost instantaneously even when it is in a for loop like the one above.
Thanks,
Kuphryn
|
|
|
|
|
If you read the time() docs, you'll see the return value is a time_t, which counts seconds.
--Mike--
"COM didn't solve the old version of DLL hell - it just provided us with a new and improved version of hell."
-- John Simmons, 1/22/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
Make sure that srand() is called exactly once in your program. Your sample code works correctly because srand() is called outside of the loop.
|
|
|
|
|
Thanks.
You are right. I did not call srand() inside the for-loop, but I did call it at the beginning of a function that I think could be recursive. I was prepare for school lastnight and was not able to look up all the code. I am certain srand() is the problem. You are right on.
Kuphryn
|
|
|
|
|
I figured probably that most Win32 API gurus hang out here, and anyway, I posted a question in the VB forum (since the app i am talking about is written in VB) and as much as I hate to cross-post, I think it is an API problem, so allow me to post a link.
Please help if you can. Would be much appreciated
The thread
--
David Wengier
|
|
|
|
|
I am using ShellExecute to open another program which is located in a subdirectory. I do this by calling it with the file param as the filename, and the directory name as the subdirectory. It works under win2k/xp/nt but not on win95/98/ME....If anyone knows why and how I can fix it it would be of amazing help!
So imagine the directory is 'stuff' and the file is 'thing.exe'
I call ShellExecute(NULL,NULL,"thing.exe",NULL,"stuff",SW_SHOW);
This works fine in 2k but not 9x!!!!!! please someone help me!
: Wherever you go, there you are, and you wish you were somewhere else :
|
|
|
|
|
did you add the Microsoft layer for unicode to your 9x project.
here is the text that is found at that link:
- Add the following two files to your project:
- UnicoWS.dll -- the Microsoft Layer for Unicode DLL
- UnicoWS.lib -- the LIB file to which you link
Note that the Microsoft Layer for Unicode does not automatically load from the $(WINDOWS) or $(WINSYS) directories. Thus, do not put UnicoWS.dll there unless you are running from a system process that is located there. Instead, keep the UnicoWS.dll in your application directory and call LoadLibrary yourself to ensure that you load the correct .dll.
- Add the following to the link options for your application (note that these libraries are not separated by commas because that is how you add them to the link list):
- First, add the following: /nod:kernel32.lib /nod:advapi32.lib /nod:user32.lib /nod:gdi32.lib /nod:shell32.lib /nod:comdlg32.lib /nod:version.lib /nod:mpr.lib /nod:rasapi32.lib /nod:winmm.lib /nod:winspool.lib /nod:vfw32.lib /nod:secur32.lib /nod:oleacc.lib /nod:oledlg.lib /nod:sensapi.lib.
- Then add UnicoWS.lib.
- Finally, add the libraries that the Microsoft Layer for Unicode uses explicitly: kernel32.lib advapi32.lib user32.lib gdi32.lib shell32.lib comdlg32.lib version.lib mpr.lib rasapi32.lib winmm.lib winspool.lib vfw32.lib secur32.lib oleacc.lib oledlg.lib sensapi.lib. In this step, omit any libraries listed after advapi32.lib whose APIs are not used in your application. However, if your application uses another component, such as MFC, ATL, or CRT, be sure to include any libraries on which the component depends.
- Compile your application.
There is other information on the Web page, I would follow the link from above.
Kilowatt
|
|
|
|
|
Use "open" as the verb, not NULL.
--Mike--
"COM didn't solve the old version of DLL hell - it just provided us with a new and improved version of hell."
-- John Simmons, 1/22/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
if you are reading some input like this:
"JOHN 444-44-4444 Student"
and you want to create some object with those 3 variables>
how can you assign every detail to the right variable provided you have all the accessors and mutators?
thanx
|
|
|
|
|
sscanf
: Wherever you go, there you are, and you wish you were somewhere else :
|
|
|
|
|
can some one tell me please how do you write the return type of a function that would return an array of characters?
thanks in advance!
|
|
|
|
|
I am assuming you want a standard "c" style array.
In that case, your function prototype should look like this:
char* SomeFunction();
|
|
|
|
|
Matt Gullett wrote:
char* SomeFunction();
I'm not so sure. How would he know the number of elements? Unless the array is zero-terminated, but then he would call it a string and not an array of characters.
I vote pro drink
|
|
|
|
|
You are correct, he asked for an "array of characters" and I assumed he wanted a string.
To return an array with no predefined terminators or size, you could do one of several things.
1. Create a custom class to deal with it.
2. Instead of using a return value, use function parameters
void SomeFunction(char** pszValue, int& iLen);
This would be good if the function needed to determine the length and allocate the memory.
OR
void SomeFunction(char* pszValue, int iMaxLen);
This would be good if the function just needed a pre-exising array of max size.
3. Use a byte array and use the first N bytes to specify the length.
I am sure there are many other ways to do this also.
Matt Gullett
|
|
|
|
|
I guess technically speaking there is a difference. PASCAL strings i think have a runlength encoding byte at index zero. I've always considered them to be synonymous while using Visuall C++.
your bad is my bad brutha!
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
I want to copy/move a file to another dir, how?
What api to use?
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
CopyFile or CopyFileEx to copy a file.
MoveFile or MoveFileEx to move a file.
|
|
|
|
|
TCHAR pszFrom[1024] = {0};
TCHAR pszTo[1024] = {0};
SHFILEOPSTRUCT shfo;
GetDlgItemText( IDC_SOURCE, pszFrom, 1024);
GetDlgItemText( IDC_DEST, pszTo, 1024);
ZeroMemory(&shfo, sizeof(SHFILEOPSTRUCT));
shfo.hwnd = AfxGetApp()->m_pMainWnd->m_hWnd;
shfo.wFunc = FO_COPY;
shfo.pFrom = pszFrom;
shfo.pTo = pszTo;
shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT;
SHFileOperation(&shfo);
See MSDN for details...
"Needless redundancy is the hobgoblin of software engineering." - Peter Darnell
|
|
|
|
|
Yeah!
This was exactly what I was looking for!
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
hello..
anybody can help me? Please help me to solve this error problem :
"error C2504: 'CRecordset' : base class undefined"
tq..
|
|
|
|