|
This sounds like a job for sockets, specifically socket 21. Here are some examples.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi, how to set form/control width and height in VC++ IDE or in code? I mean, if i want it
to be exactly 100x200pixels, how do i do that? Is there anything similar to Visual Basic?
I have a simple program that adds two numbers in array using MMX (inline assembly), the program works fine, the code as shown below,
The result on screen is :
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
which is correct,
however, if i change the line
char incamt[]={u,u,u,u,u,u,u,u};
to
char *incamt;
incamt=new char[8];
for(int j=0;j<8;j++) incamt[j]=u;
the program compiles but the result is wrong! Why is that?
Output:
9 82 117 68 17 18 19 20 17 90 125 76 25 26 27 28 25 98 -123 84 33 34 35 36
#include "stdafx.h"
#include <iostream.h>
void main()
{
const u = 5;
//an array of increment amounts to aid SIMD-style operation
char incamt[]={u, u, u, u, u, u, u, u};
//instr is an array of 24 bytes
char instr[]={65,66,67,68,69,70,71,72,73,74,75,
76,77,78,79,80,81,82,83,84,85,86,87,88};
//the following is an embedded assembly code which
//uses MMX instructions to add in parallel the
//amount u to all the bytes of the array instr
__asm
{
movq mm1,incamt //mm1 has value u in all its 8 bytes
mov cx, 3 //initialize loop count
mov esi, 0 //initialize index register
L: movq mm0, instr[esi] //mm0=next 8 bytes from instr
paddb mm0,mm1 //parallel add 8 bytes of mm0 & mm1
movq instr[esi],mm0 //move result to instr
add esi, 8 //update index register
loop L //loop back
emms //empty MMX state
} //end of assembly code
//C++ code to output the results for verification
for (int i=0;i<24;i++) cout<<int(instr[i])<<" ";
="" cout<<endl;
="" just="" to="" pause="" the="" screen
="" cin="">>i;
} //end of main
|
|
|
|
|
Hi,
I have a bit of code that works fine in non MFC C++ project. However when converting to MFC code I get the infamous C2664 compiler error. This is what I'm trying to do:
<br />
double CWork::Equation(double x[])<br />
{<br />
return (100*(x[1]-x[0]*x[0])*(x[1]-x[0]*x[0])+(1.0-x[0])*(1.0-x[0]));<br />
}<br />
<br />
double CWork::DriverFunc(double (*dblfunc)(double[]), double start[])<br />
{ <br />
min = lots of operations;<br />
return min;<br />
}<br />
<br />
void CWork::WorkIt()<br />
{<br />
double start[] = {1.,2.,3.};<br />
double min;<br />
int i;<br />
<br />
min=DriverFunc(Equation,start);<br />
}<br />
This is the error: Work.cpp(1041) : error C2664: 'DriverFunc' : cannot convert parameter 1 from 'double (double []) const' to 'double (__cdecl *)(double [])'
Any suggestions would be great.
Kash
|
|
|
|
|
Yes. You are trying to send a MEMBER FUNCTION as a "regular" (global-scope) function to CWork::DriverFunc().
You can't send pointers to member functions as "regularly" as you send pointers to "regular" functions. The discussion on this is long, and you would have no problems finding the reasons on the web. It's too long to be included here.
In any case, you have three basic options:
1) If you don't care that DriverFunc() will get a CWork-method (rather than "any" function returning double and accepting a double-array), you can change it's prototype to:
typedef double (*CWork::dblfunc)(double[]);
double CWork::DriverFunc( dblfunc func, double start[] )
{
...
}
2) Instead of passing "Equation" to DriverFunc, pass an intermediate function which will call Equation. This function will be a static member of CWork, so even if Equation() is "hidden" it will still be able to call it. This also means you'll have to pass "this". Here's how it goes:
static CWork::CallEquation( CWork* That, RestOfParamsForEquation )
{
That->Equation( RestOfParamsForEquation );
}
and then:
typedef double (*WrapperForEquation)( CWork* That, RestOfParamsForEquation );
CWork::DriverFunc( WrapperForEquation w, double start[] )
{
...
( Whever you want to call the passed function, use w(this,ParamsYouWouldLikeToPass) )
}
And then in WorkIt(), call DriverFunc with CallEquation() as the first argument
3) The third option is THE ugliest by far, slightly more complex, but does EXACTLY what you want. It will only work if Equation() satisfies a list of requirements (non-virtual, non-static), is NOT portable, and like I said: ugly. But it actual usage it's the simplest, and I like it...
The idea is basically to circumnavigate the compiler's type checking system (which is what yells at you in the first place), which WILL allow you get the address of CWork::Equation. You would have to use the value with care, but it can be done. I'll elaborate more if you want, but like I said: it's ugly...
Good luck.
-- Calius
|
|
|
|
|
Simple solutions have their own beauty
In Equation(), I will eventually need to use member variables from my CWork class so I think the first method won't fit the bill.
Please elaborate on the third option.
Kash
|
|
|
|
|
All options will work for you, since all options will result with DriverFunc() being called on the correct object. The way I usually do it is option (2), actually. It's a small price to pay (1 line of code) for the generic mechanism you gain.
Just in case we're not talking about the same thing when we're saying "option (2)", here's what I mean (in an all-madeup example):
Let's say you have a function (or a method of some class) which needs to call some "callback" function with three parameters: an int, a double, and a char. It's customary anyways to add a "context" or "userdata" argument to such callback functions (even in plain C) so you can use the same function for several callbacks, and each of the callers will pass a different first argument ("userdata") according to what was requested when the cb func was registered.
In our case we replace this "context" / "user data" with a pointer to the actual C++ instance.
We define a type for the cb func: ClassMethodCbFunc -- it gets our int,double,char arguments, plus another parameter which will become the "this".
-------------------------------------------------------------------------------------------
typedef int (*ClassMethodCbFunc)( void* This, int Param1, double Param2, char Param3 );
// (Note: "This" and not "this" !)
-------------------------------------------------------------------------------------------
The function (or some class method) which wants to use this type looks like:
-------------------------------------------------------------------------------------------
void FunctionWhichCallsMethodCb( ClassMerhodCbFunc Func, void* This )
{
...
int Res = Func( This, 1, 2.0, 'c' );
...
}
-------------------------------------------------------------------------------------------
... that is: it calls it's "Func" argument with the "This" parameter it receives, and the values for Param1, Param2 and Param3 can be anything. ("Func" and "This" go together: when one is passed for a func to another, so will the other one. Just like the "CbFunc" and "userdata" in "plain" C).
Now for the class which actually contains the method that will eventually be called:
-------------------------------------------------------------------------------------------
class CMyClass
{
public:
int MemthodBeingCalled( int Param1, double Param2, char Param3 )
{
return Param1 + Param2 + Param3;
}
static int MethodBeingCalled__Wrapper( void* This, int Param1, int Param2, char Param3 )
{
return ((CMyClass*)This)->MethodBeingCalled( Param1, Param2, Param3 );
}
}
-------------------------------------------------------------------------------------------
... Note MethodBeingCalled__Wrapper: it's static, so we can take it's address. (It does NOT receive a hidden "this" argument, since it's static!).
The way to actually use of all of this:
-------------------------------------------------------------------------------------------
CMyClass MyInstance;
FunctionWhichCallsMethodCb( CMyClass::MethodBeingCalled__Wrapper,
&MyInstance );
-------------------------------------------------------------------------------------------
Finally -- regarding the (in)famous "option (3)" :
In a nutshell, you can't take the address of class methods if they're virtual (or you can, but the function whose address you'll be getting will be resolved in linkage, not run-time, so you won't be getting the "latest implementation" -- always the same class name you mention). Also, you need to be aware of calling conventions etc...
The idea I found was this: you can circumnavigate the type checking by using a mechanism designed just (well... sorta) for that: ellipses.
If you write a function such as
void* ToVoidStar( void* Dummy, ... )
{
// Use "va_list" here to get the first argument and return it as a void*
}
And call it like:
void* Addr = ToVoidStar( 0, CMyClass::SomeMethod )
you will get the address of CMyClass::SomeMethod() in "Addr".
You then need to write a function to CALL such the method pointed to by "Addr" -- it's not a simple matter of casting it to a function-pointer type and calling it via the pointer, since in __stdcall "this" is passed in ECX.
So we need some small function, a "thunk", which accepts a "this" pointer, some parameters, and does "mov ecx,[This] ; push PARAMS ; call [Func]" (rough sketch, of course...).
This will only work for __stdcall functions, of course, which are (basically) all methods with a constant number of arguments (not ellipses!).
Maybe I should write an article on this?
-- Calius
|
|
|
|
|
Thanks for your help. I was just thinking whilst reading half way down, that you should write an article on this subject. People will definitely benefit from this.
I solved the problem using ideas from your reply and now all seems to work fine.
Thanks again.
Kash
|
|
|
|
|
I've create an MFC program with a 2x2 panes using
m_mainSplitter.CreateStatic()
and then I used CreateView
m_mainSplitter.CreateView( 0, 0, RUNTIME_CLASS(CPatEditView), CSize( 800, 600 ), pContext )
m_mainSplitter.CreateView( 0, 1, RUNTIME_CLASS( CEditPanel), CSize(cr.Width() - 800, 600), pContext)
m_mainSplitter.CreateView( 1, 0, RUNTIME_CLASS( CInfoPanel), CSize(800, cr.Height() - 600), pContext)
m_mainSplitter.CreateView( 1, 1, RUNTIME_CLASS( CMiscPanel), CSize(800, cr.Height() - 600), pContext)
In the MainFrm.h file I've got CSplitterWnd m_mainSplitter;
This box appears showing the 4 classes CPatView, MiscPanel, EditPanel, InfoPanel. I choose one and the program opens as it should.
It happens at the initialization of the Program
Seen anything like this??
Solutions??
ZoomBoy
Developing a iso-tile 2D RPG with skills, weapons, and adventure. See my old Hex-Tile RPG GAME, character editor, diary, 3D Art resources at Check out my web-site
|
|
|
|
|
After digging some more I found that MiscPanel, EditPanel, InfoPanel were FormViews that I had inserted and that they were instantiated in the InitInstance() of the App. They had been registered as Doc Templates. When opening up, the App wanted to know what type of Document I was going to use.
I've commented out the Doc types and I don't think I'll have any problem with them as I'm not printing out of those views jsut insert controls.
|
|
|
|
|
In VB 6.0 I use the following code to get the hard drive serial number. Is there an equivalent method in VC++ 6.0? How about a way to get the BIOS or CPU serial number? Could not find it in the help menu. A code snip would be really helpful. Thanks!
Sub ShowDriveInfo(drvpath)
Dim fs, d, s, t
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(drvpath)))
Select Case d.DriveType
Case 0: t = "Unknown"
Case 1: t = "Removable"
Case 2: t = "Fixed"
Case 3: t = "Network"
Case 4: t = "CD-ROM"
Case 5: t = "RAM Disk"
End Select
s = "Drive " & d.DriveLetter & ": - " & t
s = s & vbCrLf & "SN: " & d.SerialNumber
MsgBox s
End Sub
|
|
|
|
|
hi
Use GetDriveType API and c the 'See also' section in MSDN 4 related info.
rgds..mil10
|
|
|
|
|
Freddie Code wrote:
Is there an equivalent method in VC++ 6.0?
See here.
Freddie Code wrote:
How about a way to get the BIOS or CPU serial number?
Use the Win32_BIOS and Win32_Processor classes respectively.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
You can use Windows Management Instrumentation (WMI) SDK for all H/W information you need.
Use Win32_Processor,etc Classes.
Regards,
Darshan Jani
|
|
|
|
|
I get this error
[code]error C2664: '_variant_t::_variant_t(VARIANT &,bool)' : cannot convert parameter 1 from 'const char [5]' to 'VARIANT &'[/code]
when I tried to create a new variant using this code :
[code]_variant_t varID("myID", VT_BSTR);[/code]
what's wrong ?? as the docs says its okay
|
|
|
|
|
hi
There is no default constructor for _variant_t that takes the 'value' and 'VT_BSTR' 2gethor... Simply give the value only. So change ur code with the following.
_variant_t varID(L"myID");
rgds..mil10
|
|
|
|
|
I need to know all main features of MTS,
in details suffitient for passing exam
MCSD 70-015 Distributed C++,
I need articles desribing in some parts
following program:
(Read english topics)
http://www.stars-s.ru/course.asp?c_no=48&d_no=141
or
http://www.stars-s.ru/course.asp?c_no=48&d_no=17330
Do someone know good articles about ISAPI,
in a looking like that program?
Very need.
Thanks.
|
|
|
|
|
Hi guys,
I am trying to copy into a struct the contents of a buffer returned from the winpcap library, the libray function call returns a pointer to the buffer like the following type:
const UCHAR *pkt_data
I am trying to declare something to hold the data where // Packet data ??? is.
typedef struct DATAGRAM
{
UINT packetID;
ip_header ipHeader;
pcap_pkthdr wpHeader;
unsigned char pkt_data[];
} DATAGRAM;
I would prefer to keep it as UCHARS because it makes it easier to parse the data later on into headers such as tcp, so my question is how should declare the type in the struct and how can i copy the data in from the buffer??
Cheers
Packetlos
|
|
|
|
|
This "unsigned char pkt_data[];" should not pass the compiler. Insted the stucture should look something like this:
typedef struct DATAGRAM{
UINT packetID;
ip_header ipHeader;
pcap_pkthdr wpHeader;
unsigned char pkt_data[1];
} DATAGRAM;
Then if you know if you know the nuber of bytes you will be receiving you can allocate the need memory like so:
DATAGRAM* pDatat = (DATAGRAM*)malloc(sizeof(DATAGRAM) + nDataSize) or the C++ equivalent to allocate the need memory and then copy the data into pData->pkt_data as you see fit. If you do not know the data size ahead of time things get a lot more complicated and you may want to use one of the STL templates or if programming using MFC you could replace "unsigned char pkt_data[1];" with "CByteArray pkt_data;". CByteArray stores unsigned chars, because that is what a byte is.
Good Luck1
INTP
|
|
|
|
|
Hi John,
Thanks for taking time to reply, CByteArray seems to be exactly what I need, I can calculate the size of the data and set the CByteArray like this:
<br />
tempDatagram.pkt_data.SetSize(dataLen);<br />
But then how do I copy the data into the array using the given pointer to the buffer of UCHARS?
|
|
|
|
|
Sorted with:
MoveMemory(tempDatagram.pkt_data.GetData(), pkt_data, dataLen);
|
|
|
|
|
I can't use double and float variables correctly.
When I appoint a float or double values to float or double variables, The variables have 0.0 or 1.0 values. they don't have another values.(for example 0.152 or 0.53 ...)
I don't solve this.
or is there another usage float and double variables? I haven't known
deniz
|
|
|
|
|
deniz79s wrote:
or is there another usage float and double variables? I haven't known
No!
double d = 0.0;
double d = 1.0;
double d = 0.152;
double d = 123.456;
float f = 0.0;
float f = 1.0;
float f = 0.152;
float f = 123.456;
should all produce the correct results. Now if you wher trying to do something like "if( d == 1.0 )" you may be having a problem (don't do that!).
INTP
|
|
|
|
|
Hello,
it is the first time I have to distribute self-written applications
in Visual C++.
Now I am facing the following problem: My application needs some DLLs
that are not present on a standard Windows XP installation. I know that
because I can run it on my PC where I have installed Visual Studio also. When I run it on a XP-only (without VS) system, it crashes with error code xxx135 which means missing DLL.
Now what I did was using depends 2.1 to see all the DLLs that I need.
However now I do not know which ones of them I have to include with my
application installation routine. All of them would sure be overkill, since there are some standard dlls that are present on all Windows platforms I believe.
But how do I know which DLLs are definitely present and which ones I have to add to my installation package?
Thank you very much for your help.
Tony
|
|
|
|
|
There may not be a definite way to predict which DLL's are already on your customer's system and which are not but basically, if the customer is using Windows2000 or higher versions OS, you may just assume this:
If you did not specifically include any ".lib" files into your project, then you do not need to worry about DLL's, if you did, however, you will need to distribute the corresponding DLL's as well.
One more thing, if you used VC.net to develop your application, then "MFC70.DLL" must be distributed because most OS's(including Win XP) do not have that file by default.
|
|
|
|
|
Abin,
thank you very much for that information, that helps a lot.
I was really having a hard time because I used a code example
from codeguru.com on how to get the MAC Address of the PC.
http://www.codeguru.com/Cpp/I-N/network/networkinformation/article.php/c5451
I used Method 3 (GetMACAdapters) and this includes
iphlpapi.lib. Now DependencyWalker showed it relied
on EFSADU.DLL which was not present on XP Home. So I
was very confused. I now learned that although DepWalker
lists EFSADU.DLL (which is called by IPHLAPI.DLL), this
does not mean that it is explicitly linked.
I must say that I have not really understood the concept between
explicitly and implicitly linking, so I will try to learn about
it.
Thank you again,
Tony
|
|
|
|
|