开发者

Is there a console window open and am I talking to it? C++ /C#, Windows and Linux

开发者 https://www.devze.com 2023-03-29 15:47 出处:网络
I\'ve been developing an embedded C++ application as a DLL/SO (\"C\" externed) that runs on Linux (Ubuntu 11.04) and Windows(XP).As such, I have no idea if my caller application is running GUI, consol

I've been developing an embedded C++ application as a DLL/SO ("C" externed) that runs on Linux (Ubuntu 11.04) and Windows(XP). As such, I have no idea if my caller application is running GUI, console or neither. I believe stdout and stderr point to the bit bucket when there is no console connected to them so just writing to cout or cerr is harmless though I wonder if the output literally sits in some location in the pagefile/swapfile wasting space.

So my current thought is to have the caller program give me a callback function (address) and have that function look like (void)(*)(void *) where the (void *) points to a well defined struct in the caller's program where I can write error/status/whatever information. I've done sim开发者_JAVA百科ilar things before in C and C++, but I know I will have at least one C# caller. Can C# hand me such a callback? Will there be any difficulty for it/me to read the data the other might write?

Alternately, I could pop open a console and write messages to it. Can someone tell me how to do this?

I looked at popping up a message box in Windows and thkat IS A PAINFUL thing to do. Did n't look at linux. Someone have examples using char* or std::strings, not the whatever-thet-are datatypes required by windows?

FWIW, our architecture says no files, no shared memory, no named pipes and no sockets for message passing. And remembering that as a program I have no idea about writable file locations, I couldn't write to a file reliably anyway. As surely as I did some sys op would disable user writes to wherever I selected. I have to depend on the user passing accessible file path and file name to me.

Can someone please comment on my situation and ideas?

Many thanks,

Wes

COMMENT: f I understand this correctly, you are finding a appropriate way to log error/status/debug message from your C++ DLL library? And since you have no knowledge of the type of DLL-consumer (C/C++ console, C# GUI, ..), you are not sure if it's okay to write to stdout? – m3rLinEz 1 hour ago

Well, not exactly. I want to confirm that writing to sdtout/stderr when there is no console sends the output to nowhere and that it isn't bloating the swap file. I guess that translates to is it ok to write to stdout regardless of my consumer.

What it really means is, can you point me to sample code that I can use to demonstrate attaching an extern "C" DLL to a C# program and to have the program set up a callback and variable/structure/etc. and pass the addresses thereof to the DLL, which can then write data to the var/struct/etc. and call the callback. W.

0

精彩评论

暂无评论...
验证码 换一张
取 消