|
I am doing interprocess communication bwtween a, DOS console program
and a windows program using named pipes
I need to allocate an object that will remain active while communication is going on between the DOS consile app and the Windows
I know that typically object is allocated on the stack
E.g however if I use the new operator would that
Leave the object alkocated until I do a delete
|
|
|
|
|
ForNow wrote: if I use the new operator would that
Leave the object alkocated until I do a delete
Yes - see here[^].
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
what type of object are you talking about, is it class-object or any primitive type. in both case you can take services of auto_ptr and stl::list class to keep you object alive between communication and once your program exit, stl and auto_ptr will take care of destruction of your object.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
You will need to look at the various ways of sharing data between processes, it can be a little complicated.
When you use the new opperator you are allocating storage on the heap, however each process has its own heap, and the addresses in one process' heap and not usually accessible to another process, but the can be done using interprocess messaging.
Windows hooks are another very powerful way for processes to share memory, but there is no 'global' memory in windows.
And yes, you need to use delete to free the memory.
==============================
Nothing to say.
|
|
|
|
|
I am not looking for a method of communicationg between process for that I am using named pipes
What I am looking for is persistent storage storage that will remain allocated between the interprcess communocation calls
|
|
|
|
|
Dude, I'm sure *you* know what you're talking about but it's not coming through in your posts.
You have 2 programs, a "Client" and a "Server" using pipes. You have a "System" where these two program are running.
Where do you want this "persistent" object to live, in one program or the other or in the operating system (Windows)? What do you want this object for? Depending on what you are going to do with the object, some objects are better than others.
Unless you are clear as to what you want it for and where it's to live, you will get some pretty unstatisfying suggestions, like "Open a file, that'll persist"
|
|
|
|
|
OK, use 'new' and 'delete' (malloc and free) for persistent storage, or you can declare global storage during the life of the process by declaring a global array (you declare it outside of any functions normally just after where you include header files).
==============================
Nothing to say.
|
|
|
|
|
Here's my code for Digital Library system
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<iomanip.h>
#include<iostream>
//***************************************************************
// CLASS USED IN PROJECT
//****************************************************************
class book
{
char bno[6];
char bname[50];
char aname[20];
public:
void create_book()
{
cout<<"\nNEW BOOK ENTRY...\n";
cout<<"\nEnter The book no.";
cin.getline(bno,6);
cout<<"\n\nEnter The Name of The Book ";
cin.getline(bname,50);
cout<<"\n\nEnter The Author's Name ";
cin.getline(aname,20);
cout<<"\n\n\nBook Created..";
}
void show_book()
{
cout<<"\nBook no. : "<<bno;
cout<<"\nbook="" name="" :="" "<<bname;
="" cout<<"author="" "<<aname;
="" }
="" char*="" retbno()
="" {
="" return="" bno;
="" void="" report()
="" {cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<endl;}
};="" class="" ends="" here
="" ***************************************************************
="" global="" declaration="" for="" stream="" object,="" object
="" ****************************************************************
fstream="" fp,fp1;
book="" bk;
="" function="" to="" write="" in="" file
="" ****************************************************************
void="" write_book()
{
="" char="" ch;
="" fp.open("book.txt",ios::out|ios::app);
="" do
="" system="" ("cls");
="" bk.create_book();
="" fp.write((char*)&bk,sizeof(book));
="" cout<<"\n\ndo="" you="" want="" add="" more="" record..(y="" n?)";
="" cin="">>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}
//***************************************************************
// function to read specific record from file
//****************************************************************
void display_spb(char n[])
{
cout<<"\nBOOK DETAILS\n";
int flag=0;
fp.open("book.txt",ios::in);
while(fp.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_book();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<"\n\nBook does not exist";
getch();
}
//***************************************************************
// function to delete record of file
//****************************************************************
void delete_book()
{
char n[6];
system ("cls");
cout<<"\n\n\n\tDELETE BOOK ...";
cout<<"\n\nEnter The Book no. of the Book You Want To Delete : ";
cin>>n;
fp.open("book.txt",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.txt",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbno(),n)!=0)
{
fp2.write((char*)&bk,sizeof(book));
}
}
fp2.close();
fp.close();
remove("book.txt");
rename("Temp.txt","book.txt");
cout<<"\n\n\tRecord Deleted ..";
getch();
}
//***************************************************************
// function to display Books list
//****************************************************************
void display_allb()
{
system ("cls");
fp.open("book.txt",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}
cout<<"\n\n\t\tBook LIST\n\n";
cout<<"=========================================================================\n";
cout<<"Book Number"<<setw(20)<<"book name"<<setw(25)<<"author\n";
="" cout<<"="========================================================================\n";
" while(fp.read((char*)&bk,sizeof(book)))
="" {
="" bk.report();
="" }
="" fp.close();
="" getch();
}
="" ***************************************************************
="" introduction="" function
="" ****************************************************************
void="" intro()
{
system="" ("cls");
="" gotoxy(35,11);
="" cout<<"library="" ";
="" gotoxy(35,14);
="" cout<<"management";
="" gotoxy(35,17);
="" system";
="" cout<<"\n\nmade="" by="" :="" team="" alpha";
="" cout<<"\n\ngiki";
="" getch();
}
="" administrator="" menu="" admin_menu()
{
system="" int="" ch2;
="" cout<<"\n\n\t1.create="" book="" cout<<"\n\n\t2.display="" all="" books="" cout<<"\n\n\t3.display="" specific="" cout<<"\n\n\t4.delete="" cout<<"\n\n\t5.back="" to="" main="" menu";
="" cout<<"\n\n\tplease="" enter="" your="" choice="" (1-5)="" cin="">>ch2;
switch(ch2)
{
case 1: system ("cls");
write_book();
break;
case 2: display_allb();
break;
case 3: {
char num[6];
system ("cls");
cout<<"\n\n\tPlease Enter The book No. ";
cin>>num;
display_spb(num);
break;
}
case 4: delete_book();break;
case 5: return;
default:cout<<"\a";
}
admin_menu();
}
//***************************************************************
// THE MAIN FUNCTION OF PROGRAM
//****************************************************************
int main()
{
char ch;
intro();
do
{
system ("cls");
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. ADMINISTRATOR MENU";
cout<<"\n\n\t02. EXIT";
cout<<"\n\n\tPlease Select Your Option (1-4) ";
ch=getche();
switch(ch)
{
case '1':admin_menu();
break;
case '2':exit(0);
default :cout<<"\a";
}
}while(ch!='4');
}
//***************************************************************
// END OF PROJECT
//***************************************************************
I'm unable to enter the books without skipping the book code (the program omits it). Also, once i create a book entry, when i try to display all the books, at times, the file does not open.
Please point out any mistakes and resolve them as this is my project due today.
Any help would be appreciated
my program need to be able to write, read, delete and search a database.
ST
VB 6 user!
|
|
|
|
|
|
This is my first time using try and catch in c++. I know how to use it in vb, but not sure in c++. I would like to capture the error message or code, and do something, but I'm not what to put there, and the format required so it works.
I did google this, but all I could find was char str.
try {
hr = CoCreateInstance( __uuidof(AppHostWritableAdminManager), NULL,
CLSCTX_INPROC_SERVER, __uuidof(IAppHostWritableAdminManager), (void**) &pMgr);
}
catch ( char str ) {
goto CLEANUP;
}
|
|
|
|
|
try this
catch (CDBException *e)
{
AfxMessageBox("Caught Error: " + e->m_strError);
}
or use CException *e instead of the Database class variant.
In other words, you have to "catch" what something else "throws" and that depends on what routines you are calling that could throw an exception.
|
|
|
|
|
Thanks Chuck
Is it different for just straight win32?
CDBException
[EDIT]
Nevermind, it's just like vb, I just need to find the correct value for comm.
|
|
|
|
|
I don't do a lot of non-MFC these days because I find the classes so useful. It's also hard to show something useful without it containing a lot of stuff that's specific to my application and would make no sense to you. CDBException is for errors coming from CDatabase and CRecordset classes.
Here's my general exception catcher in the main loop of my application. Ignore things that are related to sending messages back to the user (client / server app).
catch (CException * cfe)
{
char exceptBuf[255];
CString ts;
CString ccnum;
if (!cfe->GetErrorMessage(exceptBuf, sizeof(exceptBuf)))
exceptBuf[0] = '\0';
#ifdef _DEBUG
AfxMessageBox(exceptBuf);
#endif
if (claim_check != NULL)
ccnum = claim_check->getClaimCheck();
else
ccnum = "000000";
ts.Format("Internal Exception Trap - %s", exceptBuf);
TheLogFile->LogThis(ccnum + CString(" : ") + ts);
sendErrorToGUI(ts, E_DEFAULTERROR, TheCommCenter, claim_check, parsed_request, inputConfig);
}
|
|
|
|
|
The first post was very helpful, I realized it was the same as vb, and I had to find the right exception, in which my case was exception literally.
I can't reproduce the error so I can test catch it, but I did the messagebox which is good enough for now. I don't expect it to ever trigger the catch anymore, since fixing all my errors.
Thanks Chunk
|
|
|
|
|
Unfortunately CoCreateInstance isn't a C++ function so it won't throw exceptions - unless someone's implemented a wrapper or something around the function that we can't see in your example.
For COM and OLE functions you have to pull apart the HRESULT return value, preferably using the Microsoft macros and/or call GetLastError/FormatMessage. It's a pain in the bum but COM and OLE are pretty old now and MS haven't quite managed to kill it off or hide it yet.
What the various return values mean can be found here[^].
Edit for English fail.
|
|
|
|
|
I didn't know it was old school, and thought it was the current way to talk to IIS 7+ web server.
It must of stopped due to one of the previous errors I made earlier. So I will use the hr check instead.
Thanks for the heads up on that.
hr = CoCreateInstance( __uuidof( AppHostWritableAdminManager ), NULL,
CLSCTX_INPROC_SERVER, __uuidof( IAppHostWritableAdminManager ), (void**) &pMgr);
if ( FAILED( hr ) )
goto CLEANUP;
|
|
|
|
|
hello guys... This error has something to do with linking. I have a static library (which contains some virtual functions) and I have taken following steps to add it to my project.
- Project Name -> Add -> Existing Item . Chose and included header file.
- Project Name -> Properties -> C/C++ -> General -> Additional Include Directories . Navigated to the folder containing the header file.
- Project Name -> Properties -> Linker -> Input -> Additional Dependencies . Gave the path including the library_name.lib
Until here, it compiles successfully. But when I derive a class from a class in this header file, it starts giving this error like: Error LNK 2001 - Unresolved External Symbols? Whats wrong with this approach? Thanks for any input.
This world is going to explode due to international politics, SOON.
modified 7-May-12 8:54am.
|
|
|
|
|
I'm not sure, but the specification of Additional Dependencies may only affect the bulding and re-building of your project. I think you have to specify additional linker directories to use and also additional libraries to include. This are usually in the same place or tab as the Additional Dependencies.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
This looks like it should work... in the header that you have included, make sure you don't have to #define anything to specify that you are using the library instead of building it. Sometimes developers use the same exact header file to build the library than what others would use to import the library and just use pre-processor directives to tell the difference.
What are the external symbols that it can't find? Are they defined in the header?
|
|
|
|
|
Albert Holguin wrote: What are the external symbols that it can't find? Are they defined in the header?
Yes. They are virtual functions and are defined in the header file.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Regular "virtual" or "pure virtual"? Makes a difference. Please post the definition from the header file so we can see.
|
|
|
|
|
Well they are regular virtual functions. An example of them can be like this
virtual void OnAdd(double n1, double n2);
virtual void OnSub(double n1, double n2);
virtual void OnMul(double n1, double n2);
virtual void OnMul(double n1, double n2);
Now I have implemented a similar application whose architecture is exactly same. Four arithmetic virtual functions in a library which I later included in the project. Then I derived a class from this lib's class and overrided those functions. It worked successfully.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
I hate to ask a question that should have been asked first. What is the exact error message. Which "symbol" is unresolved, the one in the base class or the one in your derived class? If it's the former, then the problem is that your library is not included in the linker section as an additional library. If it's the latter, then the problem is in your code and the definition of the overridden members.
|
|
|
|
|
That's in base class. But it is solved by strange method. What I did is:
- I overrided all the virtual functions in the the derived class (although left function bodies blank ).
This solved my problem. But I am thinking why it should have been a problem. I mean usually virtual functions are meant to be overriden, what if I don't want to override them at a particular point.
Well it is becoming messy, I am happy that my problem is solved for now.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
You didn't "solve" the problem, you only made the "symptoms" go away. Now you have empty functions overriding ones that may have done something useful, as you've discovered.
If it can't find the functions in the library then:
1) you didn't list the library as an input to the linker (both debug and release)
2) you are feeding in the wrong library
3) they are not in the library
You need to go back to the person / source that gave you the library and ask them about the contents and why you are having this particular problem. I'm going to stop offering suggestions on this one.
|
|
|
|