|
you can try doing this:
extern "C"
{
#include "whatever.h"
}
-c
Software | Cleek
|
|
|
|
|
Does anyone know of a good article that could help me with the following problems? I have a fairly large Visual Studio .Net solution. It is an MFC application with a number of DLLs in addition to the main project that contains the main app's gui.
For some reason, the minimum rebuild feature doesn't work too well. I need to learn more about compile time dependencies and how to avoid recompiling everything every time I change some code and perform a build or a batch build.
If I perform a clean and a build or a rebuild all, then assuming the results are a clean compilation with no errors, shouldn't I be able to run in debug mode immediately? For some reason, if I do a rebuild all of my entire MFC app and all DLLs, and then press F5 to debug, visual studio complains that the DLLs are all out of date and makes me build again. Now once I do a rebuild, followed by a build or batch build, all is okay and subsequent builds seem to be pretty smart and only build the necessary pieces based on what files changed. I don't understand this. If I do a rebuild all, that should be it. Everything should be up to date and performing a subsequent build should result in the output window showing me that all is up to date and none of the projects should recompile.
Any ideas or suggestions on how to solve this issue?
Regards,
Shawn
|
|
|
|
|
Is the following legal C++ code?
try
{
char s[10]="Error";
<br>
if (some condition)
throw s;
}
catch (const char *s2)
{
OutputDebugString(s2);
};
From what I've read I would expect the catch block to receive a pointer to stack memory thats no longer reserved for the variable s. Am I correct?
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
Steve Thresher wrote:
Is the following legal C++ code?
It appears that throw throws a copy of the data, thus preserving the scope. It is the same concept as constructing an exception in your code and throwing it.
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
Nitron wrote:
It appears that throw throws a copy of the data
Well it of course copies the char* variable but the caught variable contains the same memory address as the thrown variable. So the memory is not copied. Don't know if that is what you meant.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
If you're dealing with objects a copy is made when the object is thrown (using the copy constructor or a shallow copy if a copy constructor is not avaiable) and then the original is destroyed at the end of the try block. When it comes to strings the compiler only knows the address of the string so no copy can be made.
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
That is not my understanding. The stack will not begin to unwind until after the exception handler returns.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
If it works, it works due to something that is implementation specific.
In general, I would beat people who made code that depended on that.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
It will probably work, but shouldn't really be used. Instead, you could throw an integer index into an array of strings stored elsewhere, or allocate memory for the string and throw it, then free it in the catch() block.
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"
|
|
|
|
|
I want to program a DLL that would have three entry points. Initialize, DoDialog and Terminate. The Initialize would have a parameter that is a callback into the calling application. DoDialog would have a parameter that would be a Handle to a block of data. When called DoDialog would bring up a dialog and return when the dialog is finished. The data would be modified by the dialog. Terminate would just release things that were allocated in Initialize. So is this possible? Should I do this in MFC, .NET, something else? I also have a fair amount of non-UI C++ code that need to be ported for this dialog as well.
|
|
|
|
|
cgriffin wrote:
Can I do this?
I have no way of knowing that.
palbano wrote:
Can it be done?
Sure
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Sounds reasonable. You can program a DLL to do many things for you as long as you define a good interface. DLLs can contain classes and/or global functions that can be exported so that an application project can link to it. I like to think of DLLs kind of like how I think of classes. You figure out what you want it to do; what kind of logic/common code you want in it and design a good user interface so that other projects can link to the functions and/or classes.
We have a main app project that links to MFC extension DLLs. Use the wizard to create your ext DLLs and it is very simple. In some cases our MFC extension DLLs export class definitions (such as common dialogues). Then the main app can use #include "TheDialogueHeader.h" and then instantiate the dialogue like any other MFC class and implement a modal or modeless dialogue.
We also have DLLs that export a thread function that the application can link to and call by passing the function pointer to AfxBeginThread. Then you have a DLL with a main function that is a thread that will execute along with all of the threads in the Main App project. So your Initialize() func could be a thread or just a function that can be called and will return when finished. If it is a thread, then use the terminate function to implement the signaling logic that will cause the thread(s) in the DLL to terminate for a clean exit.
There are lots of ways to do it but what you are describing seems like a reasonable thing to do. The possibilities are endless and there are many different ways of organizing the code within your DLL. Just like a class, you can have global functions in the DLL or classes that are not exported (private to the rest of the world) that are called by the exported functions/classes (public to the world); and so on and so on.
Have fun!
Shawn
|
|
|
|
|
Thanks for your reply. I was afraid to add too much to the first post so I left out some details. What I am doing is porting code from a Macintosh project. No threading is necessary. The other thing I should mention is that I need to be able to define the dialog after compile time. I have an application that allows the user to design a custom specialized dialog. My application then generates the resources and combines that with the dialog code for the final plugin (Mac version). It seems like it would be too much trouble to write a resource table into the dll. So I was thinking that I could have an external file in my own format, read that and then create the dialog programmatically. Which platform would be best to do that in? If it's .NET is C# required for using .NET? If so then I probably can't go that way as I have to integrate my control/model code from C++.
|
|
|
|
|
Sounds challenging. I've never needed to design a dialogue at run time. I'm not experienced with managed C++ code or C#.
First of all .Net could be used for many things (you don't need to know C# to use VS .NET). You can use .Net to program an application using all unmanaged C++ code if you'd like. Visual Studio .Net has many options and capabilities that are well beyond what I've ever done.
But when I mentioned earlier that a dialogue can be designed in an MFC extension DLL, the .rc file will exist within the DLL and the .Net wizard will take care of that. So I'm only familiar with the process of creating dialogues in the .dll and allowing the .rc file to exist as part of the dll project. Of course that means that the dialogue exists at compile time which isn't what you want, so I can't help you with that particular detail. Perhaps someone with that kind of experience can chime in with some suggestions.
Shawn
|
|
|
|
|
Thanks for the help. BTW what is managed/unmanaged C++?
|
|
|
|
|
Unmanaged C++ is basic C++ where you have to do all of your garbage collection of dynamically allocated resources.
With .Net, there are many new complicated features allowing one to have .Net do garbage collection for the programmer. Managed C++ seems like a new concept to me and I've never used it before. I think Java is the same way where the compiler does all of that for you. In unmanaged C++ code you have to delete all of the objects you use new to allocated. That's part of it, in short, but there could be more complex concepts introduced by Managed C++ code.
If you want to do more, do a google search or search the article database within codeproject.com or codeguru.com and you should be able to find more detailed subject matter on that. I'm more of a basic C++ programmer with a lot of embedded design experience where we had no GUI functionality; but recently made the transition to windows programming so all of these concepts of managed code are totally new to me as well.
Regards,
Shawn
|
|
|
|
|
I'm currently testing the iphelper api.
When I request the iftable, dwInOctets is fine, but dwOutOctets always return 0. The same for all output vars in the table. Input is correct though.
Why is that? out is always 0, but my network monitor tells me different.
<br />
<br />
MIB_IFTABLE* g_pIfTable=NULL;<br />
ULONG g_ulIfTableSize=0;<br />
<br />
...<br />
<br />
GetIfTable(g_pIfTable,&g_ulIfTableSize,TRUE);<br />
g_pIfTable=new MIB_IFTABLE[g_ulIfTableSize];<br />
GetIfTable(g_pIfTable,&g_ulIfTableSize,TRUE);<br />
<br />
CString str;<br />
for(ULONG index=0;index< g_ulIfTableSize;index++)<br />
{<br />
str.Format("in=%ld out=%ld",g_pIfTable->table[index].dwInOctets,g_pIfTable->table[index].dwOutOctets);<br />
AfxMessageBox(str);<br />
}<br />
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
|
|
|
|
|
Zizilamoroso wrote:
...my network monitor tells me different.
Is it using GetIfTable() ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi everyone,
I have to generate an OLE compound file in memory. Unfortunately, I cannot use IStorage interface as the requirement is that I should not create a file on the disk. The whole thing has to be in memory.
I was wondering if there is an IMemoryStorage like interface available. Basically, I want to be able to create the storage object in memory, create a stream and write bytes to it. I was going through MS documentation and could not find much there. I was wondering if someone who has a bit more experience with this, could guide me a little.
Thanks,
Sincerely,
pankaj
Without struggle, there is no progress
|
|
|
|
|
|
Hi,
Well, came across this gem. CreateStreamOnHGlobal
However, I have another question. After I declare a IStream * object. How can I set the name of this stream object. I need to create a stream with a given name. I think the CreateStreamOnHGlobal will be suffice for me. However, I would have to set the name of the created stream object.
Any help would be greatly appreciated.
Thanks,
Sincerely,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Hi,
I did some resource-cleanup in my VC++ application, where in I deleted unused ID's, re-numbered the ID's according to MFC standards. But now my menus do not work. I checked the correspoding ID for the menu, the numerical value all seemed to be OK(unique across projects).
Can anybody help me to figure out what is going wrong?
Thanks,
Prashant
|
|
|
|
|
Rebuild the whole project/solution. RESOURCE.H is a special file and changes to it does not force all files using it to recompile.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Tim,
I have several projects of which I clean compiled the project that had the menus. Is'nt that enough?
Should I re-compile the whole solution?
Thanks,
Prashant
|
|
|
|
|
I have a rather basic MFC question. It is clear to me how to use the Create() method of a CListBox to create one. It is not clear to me what to do with it after it is created. As far as I know, it does not have a DoModal() method as a CDialog object does or something analogous to the TrackPopupMenu() method of a CMenu object.
Does anyone have an example Creating and displaying a CListBox? I want the CListBox to "return" when the user makes a selection, and then to inquire of the CListBox which selection was made.
Thanks
|
|
|
|