|
msnet wrote: CMaunder
makes a good class name.
-prakash
|
|
|
|
|
This might help u:
<br />
CString str = "123";<br />
int i = atoi( str );<br />
|
|
|
|
|
CString str;
// do some thing, like load data into string
int i = _ttoi(str.GetBuffer(str.GetLength()));
str.ReleaseBuffer();
// do some thing with i
I should be that simple.
Note: _ttoi() is the MICROSOFTS specific version of atoi(), it is used to support both MBCS and UNICODE.
INTP
Every thing is relative...
|
|
|
|
|
I have not seen the article, but,
to get the integer from a char array or CString:
int i;<br />
CString str;<br />
str = "12345";<br />
i = atoi(str);
this is this.
|
|
|
|
|
HI!
I have used the GetModuleFileName function in my MFC SDI application. The syntax is:
DWORD GetModuleFileName(
HMODULE hModule, // handle to module
LPTSTR lpFilename, // path buffer
DWORD nSize // size of buffer
);
Parameters
hModule
[in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path for the current module.
Now, the problem is with the HModule parameter. But, I don`t know how to set the handle to the module or file. What type of variable to declare. NULL is not serving my purpose.
Thanx
|
|
|
|
|
Your question is not very clear. Anyway,
If you want to get the filepath of the current exe file, then you can set it to NULL:
char str[MAX_PATH];<br />
GetModuleFileName(NULL,str,MAX_PATH);
Will get the current exe's path.
If you want the path for another file, like a DLL, then when you load it using
HMODULE hModule;<br />
hModule = LoadLibrary(...) , its handle is returned. This is the same handle for use with GetModuleFileName(...).
this is this.
|
|
|
|
|
Hi!
I hav an MFC SDI Application with two dialogs. One is for selecting source file and the other is for selecting destination file. BOth, dialogs have one edit box for browsing or editing the path of file.
Actually, I don`t want to get the path of current exe. Instead, I want to get the file path from edit box of another file. I want to get the path , which was entered in the edit box for file name on the SelectSource dialog.
Thanx a lot.
|
|
|
|
|
How are you creating both the dialogs?
If they are in the parent:
CDialog1* m_pDialog1;<br />
CDialog2* m_pDialog2;
Then you can include a pointer to the parent in dialog1:
CParent* m_pParent; //in dialog1.h
And have it initialized by the parent after the dialog creation:
m_pDialog1 = new CDialog1....<br />
.....<br />
m_pDialog1->m_pParent = this;
Then inside CDialog1:
m_pParent->m_pDialog2->m_strFileName; //whatever the variable names are.
So you can access the dialog2 from dialog1.
I hope it is clear.
this is this.
|
|
|
|
|
HI!!
Could u please suggest me some good books on MFC.
I am learning MFC. I had never worked on it earlier. But, now I am working on a project. Currently, I am trying to develop an application for converting "ini" files to "xml" files through MFC.
Thanx a lot.
|
|
|
|
|
Hello,
i'm working a VC++ class that calls stored procedures using ADO,
and i'd really like to know how to set a VARIANT to a datetime value,
without using COleDateTime class.
so instead of:
_ParameterPtr pParameter = m_pCommand->CreateParameter(
_bstr_t(sParamName.c_str()),
adDBTimeStamp,
adParamInput,
0,
_variant_t(COleDateTime(1998, 10, 1, 0, 0, 0))
);
m_pCommand->Parameters->Append( pParameter);
i'd like to go
VARIANT vMyDate;
...then some how set vMyDate to '1997-10-1 0 '
then...
_ParameterPtr pParameter = m_pCommand->CreateParameter(
_bstr_t(sParamName.c_str()),
adDBTimeStamp, adParamInput,
0,
vMyDate
);
m_pCommand->Parameters->Append( pParameter);
why do i want to do this?
I'm working on an existing program, a massive monster of program with about 60 people working on it.
the existing class has functions which add parameters of various datatypes, but theres no function for datatime.
the program uses its own custom class to handle dates and times, from which i can easily extract formatted strings
I tried to use and the COleDateTime class, but the compiler didn't recognise it:
'COleDateTime' : undeclared identifier
I'd assume that means the correct header hasn't been included.
This is a bit of a problem, my workplace is very political and anti-microsoft (even though we use vc++ and mssql!), i'm very junior here, if i add a microsoft header file there's a very good chance someone senior will take it out and back out my changes.
Is there any chance that the header has been included and i need to specify a namespace?
I tried to add what i thought was the correct header:
afxdisp.h
and i get the error:
c:\program files\microsoft visual studio\vc98\mfc\include\afxv_w32.h(14) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
can anyone offer me any suggestions?
thanks
Mat
|
|
|
|
|
_variant_t( double dblSrc, VARTYPE vtSrc = VT_R8 )
constructs a _variant_t object of type VT_R8 or VT_DATE from a double numerical value.
SkyWalker
|
|
|
|
|
thank you Mircea,
once i get my head around converting our custom date class to a double, i think that will solve my problem nicely.
thank you, you've been a great help
mathew
|
|
|
|
|
Let me confess that I am fresher in network programming can any one help me???
I made very simple server using IOCP but my server is unable to receive all the message. Here is code for my server
#include "stdafx.h"
//#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include "winsock2.h"
#include "fstream"
#include "conio.h"
#include "stdio.h"
#pragma comment(lib,"ws2_32.lib")
/*--- MACRO Defination --*/
#define SERVER_PORT htons(8888)
#define DATA_BUFSIZE 4096
#define OP_READ 0
#define OP_WRITE 1
#define OP_ACCEPT 2
/* OverlapPlus Data Used to store Ovelap info and other information need to user*/
typedef struct _OVERLAPPEDPLUS
{
OVERLAPPED Overlapped;
SOCKET sServer,sClient;
int nOperationCode;
WSABUF wbuf;
DWORD dwBytes,dwFlags;
SOCKADDR_STORAGE ClientAddr;
int nClientNumber;
}OVERLAPPEDPLUS, * LP_OVERLAP_PLUS;
void Initialize();
DWORD WINAPI ServerWorkerThread(LPVOID lpParam);
FILE *stream;
void appendLog(TCHAR* strMessage)
{
stream = _wfopen( _T("c:\\iServer.log"), _T("a") );
fputws(_T("\n"),stream);
fputws(strMessage,stream);
fclose( stream );
}
int main()
{
WSADATA wsd;
SYSTEM_INFO SystemInfo;
SOCKADDR_IN InternetAddr;
SOCKET sListen;
HANDLE hIocp;
int nClientInc = 1;
/* Initialize Winsock2 */
Initialize();
/*--- Create an I/O completion port ---*/
hIocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)0, 0);
if(NULL == hIocp)
{
printf("Error in initialization of Completion Port! Press any to exit...");
return -1;
}
/* Determine how many processors are on the system, For thead optimization */
GetSystemInfo(&SystemInfo);
/*--- Create worker threads based on the number of processors available on the system ---*/
for(int nProcessor = 0; nProcessor < (int) SystemInfo.dwNumberOfProcessors; nProcessor++)
{
HANDLE ThreadHandle;
ThreadHandle = CreateThread(NULL, 0,ServerWorkerThread, hIocp,0, NULL);
//CloseHandle(ThreadHandle); // Why We close thread Handle ?????
}
/*--- Create a listening socket --- */
sListen = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0,WSA_FLAG_OVERLAPPED);
/*--- Fill TCP Header Info for bind a socket ---*/
InternetAddr.sin_family = AF_INET;
InternetAddr.sin_addr.s_addr = htonl(INADDR_ANY);
InternetAddr.sin_port = SERVER_PORT;
/*-- Bind the socket with port --*/
bind(sListen, (PSOCKADDR) &InternetAddr, sizeof(InternetAddr));
/*--- Prepare socket for listening mode and Start the Server ---*/
listen(sListen, 5);
printf("Server Started in listen mode ....");
while(TRUE)
{
int ret;
char strBuffer[DATA_BUFSIZE];
ULONG_PTR *PerHandleKey;
OVERLAPPED *Overlap;
OVERLAPPEDPLUS *OverlapPlus,*olpClientOverlappedPlusData;
DWORD dwBytesXfered;
SOCKET sClient;
SOCKADDR_IN saRemote;
int nRemoteLen;
/*-- Accept connections and assign to the completion port--*/
nRemoteLen = sizeof(saRemote);
sClient = WSAAccept(sListen, (SOCKADDR *)&saRemote,&nRemoteLen,0 , 0);
printf("New Client! Socket number %d connected\n", sClient);
/* Allocate memory to olpClientOverlappedPlusData */
olpClientOverlappedPlusData = (LP_OVERLAP_PLUS)GlobalAlloc(GPTR, sizeof(OVERLAPPEDPLUS));
if(NULL == olpClientOverlappedPlusData)
{
printf("Error in initialization Memory! Press any to exit...");
return -1;
}
/*-- Fill OverlapPlusData -- */
olpClientOverlappedPlusData->sClient = sClient;
olpClientOverlappedPlusData->nClientNumber = nClientInc++;
olpClientOverlappedPlusData->nOperationCode = OP_READ;
olpClientOverlappedPlusData->wbuf.buf = strBuffer;
olpClientOverlappedPlusData->wbuf.len = DATA_BUFSIZE;
memcpy(&olpClientOverlappedPlusData->ClientAddr, &saRemote, nRemoteLen);
// Associate the accepted socket with the completion port
if(NULL == CreateIoCompletionPort((HANDLE)sClient, hIocp,(ULONG_PTR)0,0) )
{
printf("Error in initialization of Completion Port for server! Press any to exit...");
return -1;
}
/*-- Make Ready to Recive Data From given Port -- */
ret = WSARecv(sClient,&olpClientOverlappedPlusData->wbuf,1,&olpClientOverlappedPlusData->dwBytes,&olpClientOverlappedPlusData->dwFlags,&olpClientOverlappedPlusData->Overlapped, NULL);
}
return 0;
}
DWORD WINAPI ServerWorkerThread(LPVOID CompletionPortID)
{
/*-- Notify Starting of server -- */
printf("\nHello Server Started, I am in worker thread! \n");
HANDLE hIocp = (HANDLE) CompletionPortID;
ULONG_PTR *PerHandleKey;
OVERLAPPED *Overlap;
OVERLAPPEDPLUS *OverlapPlus,*newolp;
DWORD dwBytesXfered;
int ret;
char *strData ;
while (1)
{
ret = GetQueuedCompletionStatus(hIocp,&dwBytesXfered,(PULONG_PTR)&PerHandleKey,&Overlap,INFINITE);
if (ret == 0){
continue;
}
OverlapPlus = CONTAINING_RECORD(Overlap, OVERLAPPEDPLUS, Overlapped);
/*--- Process Data According to Operation Code ---*/
switch (OverlapPlus->nOperationCode )
{
case OP_READ:
// Process the data read Repost the read if necessary, reusing the same receive buffer as before
memset(&OverlapPlus->Overlapped, 0, sizeof(OVERLAPPED));
ret = WSARecv(OverlapPlus->sClient,&OverlapPlus->wbuf,1,&OverlapPlus->dwBytes,&OverlapPlus->dwFlags,&OverlapPlus->Overlapped, NULL);
appendLog((TCHAR*) &OverlapPlus->wbuf.buf[0]);
ZeroMemory(&(OverlapPlus->Overlapped),sizeof(OVERLAPPED));// Why we reset memory ???
printf("\n\n****Inforamtion*****\n\nClient Socket:%d \n Bytes:%d \n Buff :%s \n Client No: %d\n FLAG :%d ",(int)OverlapPlus->sClient,OverlapPlus->dwBytes,OverlapPlus->wbuf.buf,OverlapPlus->nClientNumber,OverlapPlus->dwFlags);
if (ret == SOCKET_ERROR)
{
ret = WSAGetLastError();
if ( ret != WSA_IO_PENDING)
{
// What should i do in case of Error???
//printf("Error occur at WSARecv() : %d", ret);
//ExitThread(0);
break;
}
}
break;
case OP_WRITE:
// Process the data sent, etc.
break;//…
}
}
}
void Initialize()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1, 1 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
printf("\n couldn't find a useable winsock.dll");
exit(1);
}
}
Madhu S. Kapoor
-- modified at 3:08 Saturday 15th October, 2005
|
|
|
|
|
I have created a mp3 file in memory using CMemFile... how do i play it using MCI? MCI dose not recognize the filename given for the mory file... are there any flags to be set during MCI_OPEN? Thanks!!
|
|
|
|
|
Can any one help me to find data encoding of received buffer with WSARecv() command.
Weather data send by client is in UNICODE or in ASCII format
E.g.:
WSARecv (AcceptSocket, &DataBuf, 1, &RecvBytes, &Flags, &AcceptOverlapped, NULL)
DataBuf.buff is in ASCII or in UNICODE
Regads,
Madhu S. Kapoor
|
|
|
|
|
Hello.
If I'm correct, all unicode files starts with a header. I think you should be able to detect Unicode that way. The header consists of two bytes, with the hexadecimal values FF and FE
Those two characters has two meanings:
1.
They signals that it's a Unicode file.
2.
They informs about the byte order of the machine that wrote the file.
If the Unicode file is coded the Intel way (little endian), the Unicode file starts with the two bytes FF FE.
If it's a big endian file (Motorola and others), the Unicode file starts with FE FF
|
|
|
|
|
I am not talking about file i am talking about stream ot memory buffer [char**]
|
|
|
|
|
Hello all!
I'm a VB and Assembly Programmer(Strange mix.. I know..). Well I need some help making a Dll project compile for use with VB. Below this message I will include instructions that I found for creating such a project. My problem is that I have a project (Speex.. i'm sure everyone is familiar) and I need to convert it not create a new one. Thank you in advance for the response! By the way on a scale of (1 - 10) my C++ skills are about 1.
Here is the project: http://downloads.us.xiph.org/releases/speex/speex-1.0.5.tar.gz
From what I understand all I need is:
1) A .DEF file
2) "Empty" Dll project (duno if you can change that after)
3) Include "ws2_32.lib"
*************************************************************************************
The info I found
*************************************************************************************
There have been projects I have been on in the past where there was certain functionality I needed but could not get from VB, or I had to do a complete workaround to get the functionality I could get from C++ very easily. In this tutorial I will show you how to create a C++ dll that you can call from VB. I figure instead of doing the norm, "HELLO WORLD", or "ADD NUMBER", routine I will show you how to resolve a domain name to an IP address and return that IP address back to VB, this is a little advanced for the beginner but if you have some C++ experience it wont be that bad.
For this example I will be using VC++ 6 so if you have that IDE then you will be right at home and in the case you do not use that IDE then just try to follow along and enjoy the ride!
Ok, you will first have to create a new dynamic link library project. After you create this project you will be prompted on what kind of DLL, just click empty.
After that is complete you will have to add the library ws2_32.lib to the project under project-> settings -> link -> object/modules library or the code below will not compile! Believe me when I tell you this as I had the fun of learning this the hard way and it was a nightmare.
You will now have to add three files to your project, the first being an implementation (.CPP) file, the second an interface/header (.H) file and the third a DEF (allows VB to be able to read the C++ dll function name) file.
Now lets add to the include files the function definitions for the header file. I called the header file for this demonstration c_dll_4_vb.h.
c_dll_4_vb.h
#include <windows.h>
#include <winsock.h>
// Function is used to resolve a domain name to an IP address.
// The return values are: -100 = Incorrect version of Winsock
// -200 = Cant resolve domain.
long __stdcall Resolve_Name_To_Ip
(char *pcDomainToResolve, char szReturnIP[500], int &iSize);
The function defined above will take three parameters:
• pcDomainToResolve - The name of the domain you are inquiring about.
• szReturnIP -The variable the IP address will be returned to you in.
• iSize - The length of IP address being returned without the padding.
Next you will need to add the implementation of the header file to the .CPP file. Remember that when you add the code to the .CPP file make sure you include the header file name (c_dll_4_vb.h).
c_dll_4_vb.cpp
#include "c_dll_4_vb.h"
long __stdcall Resolve_Name_To_Ip
(char *pcDomainToResolve, char szReturnIP[500], int &iSize)
{
WSADATA wsaData;
LPTSTR CompName = new char[255];
LPDWORD CompSize = new unsigned long(255);
struct sockaddr_in dest;
struct hostent *hp;
char *dest_ip;
unsigned int addr = 0;
strcpy(CompName,pcDomainToResolve);
if(WSAStartup(MAKEWORD(2,1), &wsaData) != 0)
{ WSACleanup();
return -100;
}
hp = gethostbyname(CompName);
if(!hp)
{ addr = inet_addr(CompName);
}
if((!hp) && (addr == INADDR_NONE))
{// Unable to resolve domain ip.
WSACleanup();
return -200;
}
hp = gethostbyname(CompName);
if(hp != NULL)
memcpy(&(dest.sin_addr),hp->h_addr,hp->h_length);
else
dest.sin_addr.s_addr = addr;
if(hp)
dest.sin_family = hp->h_addrtype;
else
dest.sin_family = AF_INET;
dest_ip = inet_ntoa(dest.sin_addr);
iSize = strlen(dest_ip);
// Allow the string to return to the proper size.
strncpy(szReturnIP, dest_ip, strlen(dest_ip));
dest_ip = NULL;
hp = NULL;
addr = 0;
dest.sin_family = NULL;
dest.sin_addr.s_addr = NULL;
dest.sin_addr.S_un.S_addr = NULL;
dest.sin_port = NULL;
delete [] CompName;
delete [] CompSize;
WSACleanup();
return 0;
}
Shew! Now that wasn't so bad. Ok, we have one more file to add data to but this one I swear is a breeze, this is the .DEF file. This file will let VB read the function names from the C++ dll. This is the most important file when working with C++ and VB because without it you will run into all kinds of errors.
So rather than just talking about it let see what this file looks like.
c_dll_4_vb.def
LIBRARY c_dll_4_vb
DESCRIPTION 'A C++ dll that can be called from VB'
EXPORTS
Resolve_Name_To_Ip @1
You have just completed the C++ dll. All that is left for you to do is compile the dll and it will be ready for use with VB.
So what are we waiting for lets get onto the VB stuff!
This is the easiest part of the demonstration so I wont go into detail as it is pretty much self explanatory.
Private Declare Function Resolve_Name_To_Ip _
Lib "[Add the path to the dll you just compiled]" _
(ByVal pcDomainToResolve As String, _
ByVal szReturnIP As String, _
ByRef iSize As Integer) As Long
Private Sub Form_Load()
Dim sIP As String
Dim iSize As Integer
Dim lRetVal As Long
Dim sDomain As String
sDomain = "www.yahoo.com"
sIP = String(20, "*")
lRetVal = Resolve_Name_To_Ip(sDomain, sIP, iSize)
MsgBox (Mid(sIP, 1, iSize))
End Sub
Well that just about wraps it up, but again, and I cannot stress it enough that if you run into trouble compiling the DLL make sure you have included the ws2_32.lib library in the project as explained above or you will get a ton of errors.
If you ever receive errors like, "error LNK2001: unresolved external symbol", you are most likely missing a required library. Just go ahead and add the missing library to the project and you will be good to go.
I hope this has helped you out!
***********************************************************************************
End if info
***********************************************************************************
|
|
|
|
|
Tinman0330 wrote: I'm a VB and Assembly Programmer(Strange mix.. I know..).
"Strange mix" is a definite understatement. I consider that to be the top (just put pieces toghether) and the bottom (actualy know how the pieces work). Assembly is one step below C (system-level) prgramming.
Now the ws2_32.lib (needed if using the ws2_32.dll) is related to Windows Sockets 2. Your code my use WinSockets, but that has nothing to do with your question. The .DEF is a resource file used to specify which functions you wish to export. The "@1" specifies an ordinal number (instead of name), incase you want to access the function via ordinal (never done that myself).
Use VC6 to create a simple .DLL (not an empty one), and read the comments that are generated. The notes will tell you how to export the functions without using a .DEF (which is a hold over for Win3.1 days). Play with it, add some functions, and see if you can access them from VB.
As a VB programmer you should know how to specify the VB equivalent of a function prototype, to access functions in a .DLL. If not there is a tool that comes with VB (there's a better one on the www somewhere) that will insert known Microsoft specific prototypes into your VB code. Look at the C prototypes in the VC6 header files and compare them to the VB equivalent prototypes.
Good Luck!
INTP
Every thing is relative...
|
|
|
|
|
Thank you for the reply! I created a new Dll project and looked at the examples of how to export functions. It looks like I am going to have to change each function in the project, and it is a large project. I was hoping that there would be a simple option for the linker or a short bit of code that could be added to it. Well i'm going to see if I can learn enough C++ to get a better understanding of this problem. If I am wrong about needing to change each function let me know. Thanks for the help!
|
|
|
|
|
I often run into such problem that I create a class successfully but I can't see it in the ClassView pane on the left. sometimes I can't see all of my classes. Reopenning the workspace sometimes can make the previouly hidden class appear and sometimes can not.
how come this happens? and how to prevent it?
Thank you very much!
|
|
|
|
|
I think you should install vc++ .
----------------------------
Jerry yu
Chinese
programming fans
|
|
|
|
|
I think you are using VC6.
Close the project, then try deleting the .NCB file and the .CLW files that are generated by the IDE.
If you delete the clw file, and then open ClassWizard, it will ask you about regenerating this file; say yes to it.
Also when the intellisense dies, it is useful to delete the .NCB file.
this is this.
|
|
|
|
|
|
EDIT: I think I figured out my problem, but if someone could still confirm. Basically I realized the classes that weren't showing up were just plain-old-c++ classes, and they were not derived from CObject (or more importantly CCmdTarget). At least I think that is the reason.
I'm also using VC6 and I have a number of classes that do not show in classwizard. I've tried the above a number of times and they simply do not appear. I've confirmed that the files containing these classes are listed as already in the project, but still nothing. Any idea how I get these added?
-- modified at 22:20 Tuesday 18th October, 2005
|
|
|
|
|