|
Chechi wrote:
I want to know the right code MFC to obtain the IP of the Current system...
Try gethostname() followed by gethostbyname() .
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
i am going slightly out of track, but my question is that is it possible to obtain ipaddress of a computer, when it is not connected to network. say u run mfc application on your computer and it prints out the ipaddress of your machine. i was wondering if there was any function available in mfc for this purpose.
thanks.
Avi
|
|
|
|
|
aroraavinash wrote:
i was wondering if there was any function available in mfc for this purpose.
No, but there are plenty of classes available here at CP.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I tried it and got the address as 127.0.0.1 and am not sure it is right or not..
Please do help..
May the Lord bless thee abundantly
|
|
|
|
|
Chechi wrote:
and that of allthe nodes of the network it is sharing???
Take a look at:
WNetEnumResource function continues an enumeration of network resources that was started by a call to the WNetOpenEnum function.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Hi all,
I have the following situation: I have a MyDataSource.h and MyDataSource.cpp files that define and implement a simple C++ templated class:
// MyDataSource.h file
<code>
#ifndef _MYDATASOURCE_H
#define _MYDATASOURCE_H
template <class T>
class Test
{
public:
Test(T * source);
~Test();
void TestMethod();
private:
T* m_source;
};
#endif
</code>
// MyDataSource.cpp file
<code>
#include "MyDataSource.h"
template <class T>
Test::Test(T * source)
:m_source(source)
{}
template <class T>
Test::~Test()
{}
template <class T>
void Test::TestMethod()
{}
</code>
However, when I compile this. I get the following build errors that I have been unable to resolve.
i:\Thesis\Source Code\App\TemplateTests\MyDataSource.cpp(4): error C2955: 'Test' : use of class template requires template argument list
i:\Thesis\Source Code\App\TemplateTests\MyDataSource.cpp(6): error C2244: 'Test<T>::__ctor' : unable to match function definition to an existing declaration
i:\Thesis\Source Code\App\TemplateTests\MyDataSource.cpp(9): error C2955: 'Test' : use of class template requires template argument list
i:\Thesis\Source Code\App\TemplateTests\MyDataSource.cpp(10): error C2244: 'Test<T>::~Test' : unable to match function definition to an existing declaration
i:\Thesis\Source Code\App\TemplateTests\MyDataSource.cpp(13): error C2955: 'Test' : use of class template requires template argument list
i:\Thesis\Source Code\App\TemplateTests\MyDataSource.cpp(14): error C2244: 'Test<T>::TestMethod' : unable to match function definition to an existing declaration
However, if I put the implementation in the .h file, then everything compiles fine. What do I need to do to get rid of these errors?
Thanks,
Sincerely,
Xargon
Without struggle, there is no progress
|
|
|
|
|
pankajdaga wrote:
What do I need to do to get rid of these errors?
Do what you already tried - put it into the header file.
VC++ (and almost all other C++ compilers) currently can't compile a template where the declaration of a template class is separate from it's implementation. This is addressed through the export template feature in the C++ standard. However, pretty much nobody supports it because it's a freaking pain in the arse to do. For the time being, keep it all in the same file.
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|
|
Ian Darling wrote:
VC++ (and almost all other C++ compilers) currently can't compile a template where the declaration of a template class is separate from it's implementation. This is addressed through the export template feature in the C++ standard. However, pretty much nobody supports it because it's a freaking pain in the arse to do. For the time being, keep it all in the same file.
Sorry to say, but this is not entirely correct IMHO. The OPs problem is that he didn't use the right syntax as he forgot the template parameter after the class name:
template <class T> Test<T>::Test(T* source)
It's not necessary to define the template at the point of declaration (i.e. in the header file). It's perfectly legal to define the template in a cpp file. However, it's true that the declaration and the definition has to be in the in the same translation unit, and one solution to this is to put the definition in the header along with the declaration. I usually put the definition of template member functions in a .inc (include) file that is included at the end of the .h file, but that's just my personal preference.
What is true is that you cannot export a template - you'll get a LNK2001 error. Since templates are a compile-time object it doesn't make sense to export it anyway, so the C++ standard should be changed to omit the export template feature. What you can do is export instantiations of the template (unless you use VC++ 6.0 which will give you an internal compiler error if you try).
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
You can put it in its own cpp file.
template <class T> class Test
{
public:
Test(T * source);
~Test();
void TestMethod();
private:
T* m_source;
};
// in cpp
template <class T> Test<T>::Test(T* source)
{
}
template <class T> Test<T>::~Test()
{
}
template <class T> void Test<T>::TestMethod()
{
}
This works for me 2002
Thank You
Bo Hunter
|
|
|
|
|
HI
I'm trying to link two pieces of code. One is written using MFC and the other isn't.
If I enable Debug Multithreaded DLL (in Project, Settings, C/C++, Code Generation) then the non MFC code generates multiple errors :
"error LNK 2001 unresolved external "
If I change Debug Multithreaded DLL to Debug Multithreaded then the non MFC code compiles correctly but the MFC code doesn't link and generates the following error.
"fatal error C1189: #error: Please use the /MD switch for _AFXDLL builds"
Does anyone know a way of linking the two projects together or of compiling them in the one VC++ environment but with different settings?
Thanks
Debs
|
|
|
|
|
The Debug Multithreaded DLL setting is correct. Please post your LNK2001 errors, then we might be able to assist. Typically it means you haven't linked a required import library (if referring to a system function) or that one module is compiled as C++, but the other as C, with the linker expecting mangled ('decorated') or non-mangled names, but getting the other, depending on which is which.
|
|
|
|
|
Hi Mike
The problem is that I am trying to use code that produces accurate time stamps from an NTP server in another piece of code that transmits packets of information across the network. I need to be able to accurately time the packet transmission.
However my problem is that the NTP code that I'm using only compiles correctly when its set to Link to the static libraries whilst my transmission code is based on MFC and only compiles correctly when set to link with dynamic libraries. I know I'm not supposed to mix dynamic and static links. Is there any way around this problem? Do you know if i can link each piece of code seperately and still use the NTP code to obtain a timestamp in my transmission code or if I can change either of these pieces of code from static to dynamic or vice versa?
I hope you can help me. I've been searching the web and I'm at my wits end. I've included the errors below for both settings.
Thank you
Debs
Setting as Debug Multithreaded
MFC_socket.cpp
c:\program files\microsoft visual studio\vc98\mfc\include\afxver_.h(130) : fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds
StdAfx.cpp
c:\program files\microsoft visual studio\vc98\mfc\include\afxver_.h(130) : fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds
Generating Code...
Compiling...
TSCtime.c
Generating Code...
Error executing cl.exe.
Setting as Debug Multithreaded DLL
Compiling...
MFC_socket.cpp
StdAfx.cpp
Generating Code...
Compiling...
TSCtime.c
Generating Code...
Linking...
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
MFC_socket.obj : error LNK2001: unresolved external symbol "unsigned __int64 basest" (?basest@@3_KA)
MFC_socket.obj : error LNK2001: unresolved external symbol "unsigned __int64 tscfreq" (?tscfreq@@3_KA)
MFC_socket.obj : error LNK2001: unresolved external symbol "unsigned __int64 basetsc" (?basetsc@@3_KA)
MFC_socket.obj : error LNK2001: unresolved external symbol "void __cdecl recalibrate(void)" (?recalibrate@@YAXXZ)
MFC_socket.obj : error LNK2001: unresolved external symbol "unsigned __int64 recalinterval" (?recalinterval@@3_KA)
MFC_socket.obj : error LNK2001: unresolved external symbol "unsigned __int64 lastrecal" (?lastrecal@@3_KA)
Debug/MFC_socket_try1_10Nov.exe : fatal error LNK1120: 6 unresolved externals
Error executing link.exe.
|
|
|
|
|
Thought so. It appears to be an extern "C" problem. You either need to put an extern "C" block around the declarations of these variables and functions in the header (guarded with #ifdef __cplusplus ), or you should compile the NTP code as C++ (using the /TP switch to the compiler). I generally prefer the first option, because legacy code in my experience tends to use the word new somewhere along the line...
Out of interest, why does the NTP code only work when compiled with Debug Multithreaded? What errors do you get from setting Debug Multithreaded DLL?
You can get problems with heap allocations and frees if allocations happen in one module and are freed in another.
|
|
|
|
|
Thanks Mike. Second suggestion solved the immediate problem.
|
|
|
|
|
Hi all,
I am using the ssapi.dll, to work with the source safe ole automation.
My application is a visual studio add in, it checks which project is open.
I want to get the source safe connection information (ini file, user name, password) from the open project (assuming it is connected to the source safe)
can any1 show me code on how to do that???
thanks in advanced
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I am working on a project that will need some command line exe act as a important role.
But i don't like my client know those exe. Merging those tools all into a program will cost too much time. is there any tool can hide them but i can still run them from main program.
|
|
|
|
|
If you want to hide disk files programmatically, you basically have two options:
1. Use of 'ShellExec' and the 'attrib' command to set file hide/show flags
2. Use direct manipulation of the file system. I only know how to fetch file attribute flags from FILEINFO structure, but I don't know how to set them. See MSDN & The Internet for examples.
Naturally, the final option would be to take the actual .exe file and include it to your executable as a resource. Then you could execute the tool as necessary by using ShellExec and the 'res://' path identification. I am unsure of how this ultimately works, but you might wanna try it out.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
SetFileAttributes will allow you to set a file to be hidden. Of course, the user can still enable the 'Show hidden files and folders' option in Explorer.
|
|
|
|
|
You could use a quick and dirty method of naming the file something other than .EXE and then have your program rename the file before invoking it.
|
|
|
|
|
I have a class to wrap in COM dll. There is a c++ function declare
void Draw(HDC hdc, int x, int y, int w, int h)
I warp it in IDL as
HRESULT Draw([in] int** hdc, [in] int offx, [in] int offy, [in] int width, [in] int height);
STDMETHODIMP CImg::Draw(int** hdc, int offx, int offy, int width, int height)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
image->Draw((HDC)(hdc), offx, offy, width, height);
return S_OK;
}
in this way, the hdc parameter will be IntPtr in C#
so in c# code look like
IntPtr hDC = e.Graphics.GetHdc();
if (img != null)
img.Draw(hDC, 0, 0, 100, 100);
e.Graphics.ReleaseHdc(hDC);
sounds very pretty code.
but when i turn to VB6, it doesn't work.
I write the code
Private Sub Form_Paint()
Call g.Draw(hDC, 0, 0, 100, 100)
End Sub
but compiler complain it use some type that vb can't recognize
What's the better way to make this interface be used by c#, vb6, dephi smoothly?
Any idea?
|
|
|
|
|
Hi,
I have a C++ app that uses CHtmlView (MSHTML) and sets a div contentEditable="true" to enable editing.this works fine, except the Enter key isn't being processed at all. ie. Press Enter and nothing happens. If I use IHTMLDocument2::designMode then Enter works as expected. I've verified that my C++ code isn't preventing Enter from getting to MSHTML.
If I add an OnKeyUp() JS handler and process Enter there I can add <p> or <br> ok, however this breaks if you are within an Ordered/UnOrdered list as you obviously don't want to enter a <p> tag there. I guess I can write more code to hanlde this, however I'd rather just let MSHTML handle the Enter key for me.
Note that this is only an issue when I host MSHTML in my C++ app. If I use some simple html in IE with <div contentEditable="true" ..></div> then Enter works as you would expect it to.
I've searched high and low for a way to resolve this to no avail. Any suggestions much apprecited.
Neville Franks, Author of ED for Windows. Free Trial at <a href="http://www.getsoft.com">www.getsoft.com</a>
|
|
|
|
|
I have the same problem...and went through the same trial and error...
Did you ever manage to figure out what was going on?
If so would you mind sharing?
Cheers
How do I print my voice mail?
|
|
|
|
|
Hi!!!
Many of the examples of file reading using CFile uses
the char[] variable as its input buffer i.e.
<br />
char buffer[256];<br />
file.read(buffer, 256);
<br />
when i tried using a pointer to char as the buffer i get a debug assertion failure... i.e.
<br />
<br />
char* buffer = NULL;<br />
file.read(buffer, 256);<br />
<br />
what's wrong with my code? do i have to perform initialization on the char buffer?
|
|
|
|
|
You need to set char* buffer to point to some memory, not NULL.
eg.
char* buffer = new char[256]; and don't forget to:
delete buffer; when you are done.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
you need to free up some memory for the read to work
buffer = new char[ whateversizeyouwant]
then do your read
cheers
bryce
---
Publitor, making Pubmed easy.
http://www.sohocode.com/publitor
|
|
|
|