|
Hi there, I'm trying to write a program that takes another precompiled project (was doing this in GCC but now trying in Visual Studio, bit of a jump I know....) and executes the code in it. I know this sounds like using a standard DLL but here's the bit that's got me stumped.
The precompiled project (written in C) is made up of a bunch of functions (called from the main program) but these functions call functions in the main program. I can get the first part working but I can't figure out how to make the DLL use some of the main functions. Any books I have and any internet info I've found only seem to cover the first part but not the second.
As shown in the title this is for an emulator type program.
If someone could at the very least tell what doing this is called, it would help immensely! Please ask if I need to explain more.
Thanks.
|
|
|
|
|
Probably the easiest way would be to pass function pointers to the DLL which it would use to callback into the .EXE. Here's the basic idea:
typedef void (*PMainFunc)() PMain;<br />
extern "C" void SetCallback(PMainFunc pCallback);<br />
<br />
void InMainCalledFromDll()<br />
{<br />
}<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
SetCallback(&InMainCalledFromDll);<br />
}
There are many variation of this theme, for example passing the address of a structure of function pointers or using virtual functions. This should get you started.
Steve
|
|
|
|
|
It sounds like you have a circular dependency, where your library expects the program using it to have functions with specific names. This is a questionable design, but legal as long as it's a static-link library, not a DLL.
A better design is to have the app pass a pointer to a callback function, which the library code calls as needed.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Thanks for the replies. Yeah I realise the overall design is questionable but it's basically necessary, the program is to employ C code that's been written for a Microchip device and emulate the already written OS it runs on top of. The idea being I can write and test code without having to build the actual device that uses it straight away.
Thanks again!
|
|
|
|
|
I am new to c++,VC++. I am working on a project where i difference two files.
I am passing in the Header Names as commandline arguments in the following format.
cat:dog:pig:don key:owl.
cat,dog and pig is ok. But "don key is not getting recognised.It is read as just "don". I should be able to read it as "don key" or i might replace the white space with something else.
Please help.
-- modified at 19:11 Monday 13th February, 2006
|
|
|
|
|
The command-line parser uses spaces as a limiter. To override this you must place quotes around parmeters that have spaces:
someexe cat dog pig "don key" owl
or
to keep your original format:
someexe "cat:dog:pig:don key:owl"
this would be read as one parameter.
-- modified at 19:24 Monday 13th February, 2006
|
|
|
|
|
|
I was wondering if anyone knew of a way, if it is even possible, to declare a macro with a variable parameter list. Say I have a function with a long name, in a class with a long name, in a namespace with a long name and I want to remame it with a short name
LongNamespaceName::LongClassName::LongFunctionName(int, ...);
#define shortname(x, ???) LongNamespaceName::blah Never mind the merits of good or bad or why, I just want to know if and how.
I don't think it is possible, but I will never know if I don't ask.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Unfortunately, you can't use variable length argument lists with macros. You can sort of fudge it by surrounding the arguments with parentheses, but then you end up with parentheses in the expansion, so it's only useful if the parentheses are legal when expanded.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
A recent rev to the C spec allows this - search for __VA_ARGS__ - but AFAIK this hasn't made it into C++ yet.
You can make an alias for a namespace, though:
namespace foo = ReallyLongHardToTypeName;
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
I have a static control(derived from CStatic) and it contains two lines. I want to set the color of the first line to blue and the second line to red. Currently I am using the CDialog::OnCtlColor and using the SetTextColor function to set the color. However it sets the color for the whole static control i.e. both the lines. Can someone help?
|
|
|
|
|
The OnCtlColor message doesn't give you that amount of control over the text lines that gets coloured.
In cases like that where you need very flexable colour control, you might as well use the rich edit control, or search for one the various HTML-CStatic hybrids that are available on this site.
I Dream of Absolute Zero
|
|
|
|
|
LeeeNN wrote: Currently I am using the CDialog::OnCtlColor and using the SetTextColor function to set the color. However it sets the color for the whole static control i.e. both the lines. Can someone help?
Try this Control http://www.codeproject.com/staticctrl/pphtmlstatic.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Im want to do some messaging through an RS232, but dont know where to start really... Does anyone have any good examples or know where to find them using an RS232 Connection?
"There are 10 types of people, those who understand binary, and those who don't."
- Somebody, not me.
|
|
|
|
|
|
Thanks a ton, very helpful...
-Jason
"There are 10 types of people, those who understand binary, and those who don't."
- Somebody, not me.
|
|
|
|
|
Is there a function in Win32/MFC that will determine if a file name is valid?
I'm looking for something that tests for the conditions mentioned in this article under the Naming Conventions heading.
"My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine
|
|
|
|
|
There are probably lots of ways, but try this:
IMoniker* pMonk;
HRESULT hr = CreateFileMoniker(OLESTR("C:\\auxa.txt"), &pMonk);
if ( SUCCEEDED(hr) )
{
pMonk->Release();
}
Be sure you've called OleInitialize , CoInitialize or CoInitializeEx somewhere in your process.
Steve
|
|
|
|
|
Doesn't work. (they're all valid)
I went through a slew of file based functions, including things like GetShortFileName, hoping for a failure if the name was invalid, none worked.
I guess I'll just use a regular expression.
"My dog worries about the economy. Alpo is up to 99 cents a can. That's almost seven dollars in dog money" - Wacky humour found in a business magazine
|
|
|
|
|
I used the following code:
--------------------------
void IsValid(LPCOLESTR pFileName)
{
IMoniker* pMonk;
HRESULT hr = CreateFileMoniker(pFileName, &pMonk);
if ( SUCCEEDED(hr) )
{
pMonk->Release();
wcout << L"'" << pFileName << L"' is valid.\n";
return;
}
wcout << L"'" << pFileName << L"' is NOT valid.\n";
}
int main(int argc, char* argv[])
{
OleInitialize(NULL);
IsValid(OLESTR("auxa.txt"));
IsValid(OLESTR("aux.txt"));
IsValid(OLESTR("aux .txt"));
IsValid(OLESTR("C:\\ filename.txt"));
IsValid(OLESTR("C:\\auxa.txt"));
IsValid(OLESTR("C:\\aux.txt"));
IsValid(OLESTR("C:\\aux .txt"));
OleUninitialize();
return 0;
}
And got this in output:
-----------------------
'auxa.txt' is valid.
'aux.txt' is valid.
'aux .txt' is valid.
'C:\filename.txt ' is valid.
'C:\auxa.txt' is valid.
'C:\aux.txt' is NOT valid.
'C:\aux .txt' is NOT valid.
Seems to work only for fully qualifed paths. Seems to fail the trailing space rule in any case.
Steve
|
|
|
|
|
I don't know if i'm on the right forum but for god sake help. PLEASE.
i'm on windows xp home edition and every time i try to open my documents or my folders the page comes up in blocks and then microsoft sends a message saying it must close the program, i check the error report then it comes up Dr Watson postmorton debugger,then closes. Help i've run 3 different anti-virus scans and only one showed an error (??chost) but cause it came up as an error it carn't delete it. please if anyone can help remove the virus or what ever the prob is can you site it.
please tell me what it is and how to remove it cause i really need to gain access to my files . thanks
sparra06
|
|
|
|
|
I'm using Visual Studio 2005 to edit my icons, but I cannot figure out how to paste a 256 color image onto my 32x32x256 icon. It always comes through 16-color. Any ideas?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi,
At the restart of the main application, I need to reload all the child windows that were opened and visible during the previous run of the application. I used persistent frames to obtain the state of each of the child windows and write into the registry. But during application restart I need these windows to come up automatically (that is those child windows that were not closed before the main application was closed).
Its the same as saving the workspace in visual C++ and when the workspace is opened again, all the child windows would come up automatically.
Can anyone help me with this.
Thanks
Vijay
|
|
|
|
|
hi
I need to get a list of all the computers on the LAN which are ON i.e. which are up.
For that i think the best option is to broadcast a connection request to all the systems on LAN and those who are up will be programmed to send something like their address.
I don't know how to broadcast a connection request. I have already made a client/server program in VC++, so i know the basic concepts.
If there is some material on NET, please refer.
thanx
|
|
|
|
|
The Q&D way is to send a broadcast PING on the network you are interested in. However, this has a few downsides.
You typically need Administrator access to send on the broadcast IP address, not all machines are required to respond to PING, and IT people tend to not like broadcast-ed traffic.
You might want to have a look at the network enumeration functions, and have a look at the "Enumerating Network Resources" sample for further options.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|