|
Try searching in the MSDN for the API function AllocConsole . The console functions let you do this sort of thing.
Software Zen: delete this;
|
|
|
|
|
sorry, i have no msdn, does anyone have any other solution, and the system call doesn't seem to work
|
|
|
|
|
|
Hi,
I'm trying to create a dll, but I get an LNK2001 error at a line on my .def file. Why does this happen? I thought .def prevented this. Thanks.
|
|
|
|
|
Anonymous wrote:
...I get an LNK2001 error at a line on my .def file
And that line would be?
Anonymous wrote:
Why does this happen?
Have you looked here?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
|
Hi,
I'm trying trying to re-compile some source code. The code was written in VC++. However, the writer only included the .h, .c, and a file called makefile. Hence, I'm having trouble re-compiling becuase I don't know the proper settings for the project. I get a lot of LNK2001 errors. I went through the "makefile" and it looks more like the type used on UNIX. Could someone tell me what it is? It's NOT a .mak file. Can I use it to set my project settings?
# Nmake macros for building Windows 32-Bit apps
!include <ntwin32.mak>
# If the rpc include directory is not included in the standard path
# you have to give the path to it here.
RPCINCLUDEPATH = ..
# If the rpc library is not included in the standard lib path
# you have to give the path to it here.
RPCLIBPATH = ..\bin\\
DEFINITION = ONCRPC.DEF
OBJS = CLNT_RAW.OBJ \
XDR.OBJ \
CLNT_TCP.OBJ \
CLNT_UDP.OBJ \
PMAP_RMT.OBJ \
RPC_PROT.OBJ \
SVC_AUTU.OBJ \
SVC_AUTH.OBJ \
SVC_RAW.OBJ \
SVC_RUN.OBJ \
SVC_TCP.OBJ \
SVC_UDP.OBJ \
XDR_MEM.OBJ \
XDR_REC.OBJ \
AUTH_NON.OBJ \
AUTH_UNI.OBJ \
AUTHUNIX.OBJ \
BINDRESV.OBJ \
CLNT_GEN.OBJ \
CLNT_PER.OBJ \
CLNT_SIM.OBJ \
GET_MYAD.OBJ \
GETRPCEN.OBJ \
GETRPCPO.OBJ \
PMAP_CLN.OBJ \
PMAP_GET.OBJ \
PMAP_GMA.OBJ \
PMAP_PRO.OBJ \
PMAP_PR.OBJ \
RPC_CALL.OBJ \
RPC_COMM.OBJ \
SVC_SIMP.OBJ \
XDR_ARRA.OBJ \
XDR_FLOA.OBJ \
XDR_REFE.OBJ \
XDR_STDI.OBJ \
SVC.OBJ \
BCOPY.OBJ \
NT.OBJ
all: oncrpc.dll portmap.exe
clean:
del $(OBJS) oncrpc.lib oncrpc.dll oncrpc.exp portmap.obj portmap.exe ..\rpcgen\oncrpc.dll
portmap.exe: oncrpc.lib portmap.obj
$(link) $(conlflags) $(ldebug) -out:portmap.exe PORTMAP.obj $(RPCLIBPATH)oncrpc.lib $(conlibsdll) wsock32.lib
copy portmap.exe ..\bin\pm_ascii.exe
oncrpc.lib: $(OBJS) oncrpc.def
$(implib) /out:oncrpc.lib /def:$(DEFINITION) $(OBJS)
oncrpc.dll: $(OBJS) oncrpc.lib oncrpc.exp
$(link) /DLL /out:oncrpc.dll -entry:_DllMainCRTStartup$(DLLENTRY) $(ldebug) oncrpc.exp $(OBJS) $(conlibsdll) wsock32.lib advapi32.lib
copy oncrpc.lib ..\bin
copy oncrpc.dll ..\bin
copy oncrpc.dll ..\rpcgen
.c.obj:
$(cc) /I$(RPCINCLUDEPATH) /DONCRPCDLL $(cdebug) $(cflags) $(cvarsdll) $*.c
|
|
|
|
|
Can you not just import makefile into a new VC++ project?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Is anyone familar with warning C4273? I get this while compiling a static library. When I try to compile an app which uses the lib, I get a link error. I assume the warning and the error are related. Thanks.
|
|
|
|
|
Per MSDN:
The specified member function was declared in a class with dllexport linkage, and then was imported. This warning can also be caused by declaring a member function in a class with dllimport linkage as neither imported nor static nor inline.
The function was compiled as dllexport.
Does any of this apply to your situation?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
The library was written in native C. I think my problem has to do with the .def file. Not sure.
|
|
|
|
|
How does one include a pre-made ".def" file into a project? I tried to drag and drop into the source files section but this does not seem right. Is it set in the projects setting?
|
|
|
|
|
Anytime I add a file to a project, I use the Project/Add to Project/Files menu option. That said, I'm not sure the linker would automatically know to use a .DEF file.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Simply adding the file does not do it. The Project folders setting needs to be changed. However, I can't seem to edit the inputs.
|
|
|
|
|
I did not find a setting in the Project Settings dialog box, Link tab, for the /DEF linker switch. Perhaps you'll need to modify the .DSP or .MAK file manually to add it.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Within my program, I want to bring a window to another program to the foreground. I'm doing the following:
CWnd *pFV;<br />
<br />
pFV = CWnd::FindWindow(NULL, _T("Another Program Title"));
Then if FindWindow was successful, I call pFV->SetForegroundWindow() to bring it to the front.
This works great in most cases, but it sometimes fails... The program I'm referencing changes its name in the titlebar depending on which options are selected. I don't have the source to the program, so I can't modify it. How can I get a pointer to this window without knowing what the title is going to be? Is there a way to link to the process name?
I also know that the first x characters in the title will always be the same. Is there some way to search through all the titles of open windows to do a comparison?
Any help would be greatly appreciated. Thanks.
Todd Krzeminski
tkrzeminski@nlxcorp.com
|
|
|
|
|
The most efficient method here would be to use Microsoft Spy++ to find out the class name of the window, then use FindWindow on the class name instead of window caption.
Just start Spy++, start the target program, and detect it's class name. If you do not know how to use Spy++, refer to it's help files, they are very throughout.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I tried that, but for the class name I get an long string (Afx:4000...) that seems to vary each time I run it. Am I doing something wrong?
Thanks,
Todd Krzeminski
tkrzeminski@nlxcorp.com
|
|
|
|
|
This type of class name means that the program uses MFC to register a new class for itself always when it is run.
This means that the class name of the window is not an usable option. The other poster suggested using window enumeration callback routine. I find this the best alternative as well. Just get the caption of each window and compare X characters of it to see if there is a match. I remember you saying that certain characters of the window title always remain constant, so this would sound like the best course of action.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
tjkrz wrote:
How can I get a pointer to this window without knowing what the title is going to be?
How about the window's class name?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
If you can't use the class name, then the best alternative is to use EnumWindows. This will call a function you provide. With each callback you get will need to retrieve the titlebar text and do your own matching. Once you've found the window you can return FALSE to stop the enumeration early.
Hope that helps.
--
Joel Lucsy
|
|
|
|
|
Thanks, I got it working with EnumWindows.
|
|
|
|
|
Hi everyone,
I got myself a copy of Andrei Alexandrescu's Modern C++ Design after hearing a lot of good things about it. The book is on the heavy side though. I never used templates much before, but this book seems to open new vistas for great design.
I read the first chapter last night and was thinking about it the whole day. The topic of discussion being policy classes. Everything seemed fine, but I cannot understand one point:
He states that [B]Make the destructors of the policy classes protected and non-virtual[/B]
However, will this not lead to problems if someone instantiates a derived class through a base class:
Here is a small example, I am sure you guys have seen this millions of times. I, however, am a novice. So please advice:
Here is a small pseudo policy and a derived class:
<code>
template <class T>
class SuperBase
{
public:
virtual void OpenSource()
{
std::cout << "In superbase opensource" << std::endl;
}
};
template <class T>
class MyDataSource: public SuperBase<T>
{
public:
MyDataSource()
{
some = new T;
}
void OpenSource()
{
std::cout << "In mydatasource open source" << std::endl;
}
private:
T * some;
protected:
~MyDataSource()
{
std::cout << "In destructor of my source" << std::endl;
delete some;
}
};
Now, in my main program if I do this:
SuperBase<int> * temp = new MyDataSource<int>;
temp->OpenSource();
delete temp;
</code>
This will of course never call the destructor of MyDataSource.
Am I missing a design detail here. Are these templated classes never supposed to be derived from. How can I make sure such heritance is safe (in keeping with the design principle here).
Thanks a bunch.
Xargon
Without struggle, there is no progress
|
|
|
|
|
Well, a golden rule in C++ is that if you have a virtual method in a class, you should also add a virtual destructor. If you've made one method virtual then you have implied that the class may be inherited. And if that's the case, anything but a virtual destructor would be bad design as it will most likely leak.
I think you should add a virtual destructor in the SuperBase class. That will make sure the MyDataSource<T> destructor is called (since MyDataSource<T> inherits from SuperBase).
I haven't read (unfortunately) this book you mention yet, so I'm not really 100% about the terminology. But is this really how a policy class is supposed to work? I thought policy classes were something along the lines of traits in C++ which are mostly static classes relying mainly on type and method names.
--
20 eyes in my head, they're all the same![^]
|
|
|
|
|
I figured out what my mistake was:
- The destructor of the policy class is supposed to be protected, not the derived class. Basically, Andrei breaks from the rule that Inheritance behavior is IS-A. he rather prefers..Inheritance as USES. I would probably disagree with him on that.
Just to be clear, let me create a small example:
Recently, I had to write a small module and that reads a binary file generated by some system, extract the data, and put it in an SQL server database. I had to do it in C++. The trick is to try and see which method suits the best for the particular design:
- I wanted the design to be a bit generic, so people could expand on it. So I had a base class like so (for simplicity let us say it has only one method for writing to database called WriteExperiment():
class DataSourceBase
{
public:
DataSourceBase();
virtual ~DataSourceBase();
virtual bool OpenSource(std::string & connectionStr);
virtual bool CloseSource();
virtual bool WriteExperiment(int data);
};
Now, for my need I inherit from this class:
class SqlServerSource: public DataSourceBase
....
// You know the drill...
Then I have a writer class basically which takes a reference to a DataSourceBase object and polymorphism does the rest.
With the template based method, I would do the same as:
class SqlServerSource
{
public:
SqlServerSource()
{}
bool OpenSource(std::string & connectionStr){}
bool CloseSource() {return true}
bool IsOpen()
{
return true;
}
protected:
~SqlServerSource(){}
};
template <class DataSource>
class WriteExperimentPolicy
{
public:
WriteExperimentPolicy() {}
void SetDataSource(DataSource * source)
{
m_pDataSource = source;
}
bool WriteExperiment(int val)
{
// Do something here
return true;
}
private:
DataSource * m_pDataSource;
protected:
~WriteExperimentPolicy();
};
// My class which uses both of them
template <class DataSource, class WritePolicy>
class MySource: public DataSource, WritePolicy
{
public:
MySource()
{}
void Test()
{
if (this->IsOpen())
this->WriteExperiment(1);
}
};
// In the main application:
typedef MySource<SqlServerSource, WriteExperimentPolicy<SqlServerSource> >Source;
int main()
{
Source temp;
temp.Test();
return 0;
}
I have just read the first chapter, but it looks like I can learn a lot from this book. I would never even think of doing this before. I was very hesitant with templates and never used it much. I am a very novice programmer and got miles to go still
Pankaj
Without struggle, there is no progress
|
|
|
|