|
Hi guys,
I am new to using inheritance in C++ programming .I am trying to implement some of the missing methods in C++ string class using inheritance.Even thoughi have coded the methods i am not able to apply those on the string data type,.Can any of you help me out on this
Thanks
Sas
|
|
|
|
|
Ummm - what missing methods are you referring to? Are you talking about std::string, or MFC/ATL CString?
Phil
|
|
|
|
|
I am talking about methods like rightJustify,strip() etc.. and i want to implement them in the inherited class.I wanted toknow how the declaration & implemantation of header will be..btw, am talking about std::string
your help will be greatly appreciated!!
Thanks
Sas
|
|
|
|
|
Dear forum members,
I have controls (UserControl) designed in C#.
Can anyone tell me how I can embed them in MFC dialogs/views ?
Any sample code will be very helpful.
Thanks in advance.
|
|
|
|
|
Hi,
I am working on an unmanged user interface .I am using the services of a COM Executable that is also unmanaged.
BUt to get the handle of the Com executable ,I have to go through Managed DLL(i.e this is the requirement).
I am able to retrieve the handle successfully, but some methods are failing.
The HR error value in these is 0x80131531
MSDN says that this exception thrown by the marshaler when it encounters an argument of a variant type that
can not be marshaled to managed code
I am helpless about this error.
Can anybody suggest some way to rectify it?
Thanks in Advance!
Sanjay
|
|
|
|
|
Can someone help me? I have VS C++ 2003. Am try to make a manged project. But there is no Managed C++ Application in the project box. What do I need to do.
|
|
|
|
|
I have two projects, one unmanaged. The other is managed using stl lists of classes declared in the unmanaged project. When building the unmanaged project, anywhere the lists are used produces these linker errors.
MotionTimelineControl.obj : error LNK2022: metadata operation failed (80131187) : Inconsistent method declarations in duplicated types (types: tools.thoth.MotionEventController; methods: .ctor): (0x06000013).
MotionTimelineControl.obj : error LNK2022: metadata operation failed (80131187) : Inconsistent method declarations in duplicated types (types: tools.thoth.MotionEventController; methods: load): (0x06000017).
MotionTimelineControl.obj : error LNK2022: metadata operation failed (80131187) : Inconsistent method declarations in duplicated types (types: tools.thoth.MotionEventController; methods: getEventItr): (0x06000022).
MotionTimelineControl.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: tools.thoth.MotionEventController; fields: m_event): (0x04000011).
tools.thoth.MotionEventController, uses lists of classes from the unmanaged project, and MotionTimelineControl.obj is from a class that takes a MotionEventController as an argument to two methods.
The only solution i have found to get around the linker error is in the unmanaged project is to create a class that is not used (the constructor is private), with public stl lists with the classes used in the managed project. i.e. (MotionTimeLineEvent is a class declared in the unmanaged project.)
if the managed project uses
void doFunc(list<motiontimelineevent>::iterator iter);
then declaring a public variable in the unused class:
list<motiontimelineevent>::iterator m_iter;
would clear up any linker errors having to do with lists of MotionTimelineEvents.
if anyone has any clue on how to resolve the inconsistent metadata, please throw me a bone, i have tried most available solutions but, any suggestions would be greatly appreciated.
|
|
|
|
|
while I'm running my app, everything seems to be working fine. Once I exit the app I get the following messagebox:
INTERNAL ERROR<br />
<br />
Unhandled exception in Debugger::HandleIPCEvent<br />
<br />
Event id = 0x225<br />
<br />
Exception code = 0xc0000005,Eip = 0x7928c531<br />
<br />
ProcessID = 0x4a4(1188), Thread id = 0x384(900)
then I get a messagebox telling me the following:
An unhandled exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
I recently deleted some controls and their message map entries for a dialog, and I wasn't getting this error before, does anyone know what this might be?
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Hai Friends,
In my project i have lot of drwaing in a MDI child form. The form has scrollable contents also.
I want to show miniature of the drwaing form in child control something like picturebox or some other containers.(show the full drawings)
Anyone have any idea??
Thanks in advance
Anish
|
|
|
|
|
I am using alarm() to time a process.
Is there something with which i can measure by milliseconds ?
The alarm() in C++ allows only seconds and not anything lesser than that.
I did try ftime() and time(),But i need something to timeout automatically.
I am using RH linux and g++ 3.2
Thanks
|
|
|
|
|
Try GetTickCount();
43 68 65 65 72 73 2c
4d 69 63 68 61 65 6c
|
|
|
|
|
I am doing it on Linux with a gcc compiler 3.2
|
|
|
|
|
Ups, I didn't notice.
43 68 65 65 72 73 2c
4d 69 63 68 61 65 6c
|
|
|
|
|
try using signal()
u can do anythin with it
|
|
|
|
|
Hello folks!
I urgently need to go through a C++ source code for checking whether in an algebraic expression the brackets and braces () and {} are nested. I have been trying to write it for a while now, actually I tried two ways but thats too much loops one in another for my level. Thanks, you would save me!
|
|
|
|
|
Hi,
In my Opinion, stack would be the better choice when task is expression parsing.
Thanks
Jitendra
|
|
|
|
|
Hello programmers,
I having problems with a combo box. I populate the combo box with strings. I am trying to write a fucntion that displays a message box and prompts the user to select a item from the combo box when the current selection is empty.
|
|
|
|
|
If nothing is selected the SelectedIndex property is null so you can use that or you can set some default value of SelectedIndex so that something is always selected by default. At the end you can put an empty string and set SelectedIndex to it's index and test if combo->Text is empty.
--Nikola--
modified 7-Dec-20 21:01pm.
|
|
|
|
|
I write one dll in Managed C++, I add reference to WebProject, all done but when I open webpage design it occur an error "failed to load design..." someone can help me how to repair it.
thanks
Nho'c Ti`
|
|
|
|
|
I would like to use Extended MAPI in my C# programm, read a String-Property from a Message.
For this purpos I write a managed/unmanaged C++ DLL.
I have an Object* from mail.MAPIOBJECT which should be of the type IUnknown according to Microsoft documentation.
I need an LPMAPIPROP for HrGetOneProp(LPMAPIPROP pmp, int ulPropTag, LPVOID lppPro) which can be (I'm not sure, but I found it on a webpage) a pointer to a IUnknown.
But what are the lines between?
I tried:
<br />
static String* GetStringProperty(Object* MAPIObject, int PropertyNumber) {<br />
String* Val; <br />
char* bufVal;<br />
IntPtr pUnk = Marshal::GetIUnknownForObject(MAPIObject);<br />
LPMAPIPROP pMsgMAPI = (LPMAPIPROP)pUnk.ToPointer();<br />
if (pMsgMAPI!=0) {<br />
int hRes = HrGetOneProp(pMsgMAPI, PropertyNumber, (LPBYTE*)&bufVal);<br />
if (bufVal != 0) {<br />
if (hRes == 0) {<br />
Val = Marshal::PtrToStringUni(bufVal);<br />
}<br />
MAPIFreeBuffer(bufVal);<br />
}<br />
}<br />
return Val;<br />
}<br />
pUnk gets a Value but pMsgMAPI/IUnknown says undefined.
Please help
Bernhard Mähr
Spam these adresses: SpamCatcher@CuteConnections.Com Delete@CuteConnections.Com Recycle@BillyX.com Muell@BillyX.com
|
|
|
|
|
Is MAPIObject holding an actual object instance?
|
|
|
|
|
Hi,
Please see following codes on CRC 32:-
CRC32.h
#ifndef _CRC_32_H_EA6C0EE0_BC30_11d5_B625_A58C4DF45B22_INCLUDED
#define _CRC_32_H_EA6C0EE0_BC30_11d5_B625_A58C4DF45B22_INCLUDED
#if MSCVER > 1000
#pragma once
#endif
#ifndef WINDOWS
#include <windows.h>
#endif
#define WM_CRC_THREAD_DONE WM_APP + 0X2DB1
class CRC_32
{
typedef struct tag_CRCstruct
{
CRC_32 *pCRC_32;
TCHAR FileName[MaxPath];
LPBYTE pByte;
UINT size;
HWND hWnd;
HANDLE Thread;
} CRCStruct, *LPCRCSTRUCT;
public:
CRC_32();
DWORD CalcCRC(LPCTSTR FileName, HWND ProgressWnd = NULL);
DWORD CalcCRC(LPVOID buffer, UINT Size, HWND ProgressWnd = NULL);
private:
static DWORD WINAPI CRC32ThreadProc (LPVOID lpVoid);
void Calculate (const LPBYTE buffer, UINT Size, ULONG &crc);
ULONG Reflect (ULONG ref, char ch);
ULONG Table[256];
};
#endif
******************************************************************************
CRC32.cpp
#include "CRC2.h"
#include <io.h>
#include <fcntl.h>
#include <share.h>
#include <tchar.h>
#include <commctrl.h>
#define BUFFERSIZE 102400
DWORD WINAPI CRC_32::CRC32ThreadProc(LPVOID lpVoid)
{
LPCRCStruct pCRCSt = (LPCRCStruct)lpVoid;
ULONG CRC = 0xFFFFFFFF;
HWND Progress = NULL;
if (::IsWindow(pCRCSt->hWnd))
{
Progress = pCRCSt->hWnd;
::PostMessage(Progress, PBM_SETPOS, 0,0);
::PostMessage(Progress, PBM_SETRANGE32, 0, 100);
}
if (pCRCSt->pByte)
{
for (UINT offset = 0; offset < pCRCSt->size; offset += BUFFERSIZE)
{
pCRCSt->pCRC_32->Calculate(pCRCSt->pByte + offset, (pCRCSt->size - offset > BUFFERSIZE) ? BUFFERSIZE : (pCRCSt->size - offset), CRC);
if (::IsWindow(Progress))
{
int percent = offset > pCRCSt->size ? 100 : (int)(((double) offset / (double)pCRCSt->size) * 100);
::PostMessage(Progress, PBM_SETPOS, PERCENT, 0);
}
}
}
else if (pCRCSt->FileName)
{
LONGLONG done = 0;
UINT size = BUFFERSIZE;
BYTE buffer [BUFFERSIZE];
int theFile = _tsopen(pCRCSt->FileName, _O_RDONLY | _O_SEQUENTIAL | _O_BINARY, _SH_DENYWR);
if (theFile != -1)
{
_lseekie64 (theFile, 0L, SEEK_SET);
while (size == BUFFERSIZE)
{
size = _read(theFile, buffer, BUFFERSIZE);
if (size)
{
pCRCSt->pCRC_32->Calculate(buffer, size, CRC);
if (::IsWindow(Progress))
{
//update progcess bar
done += size;
int percent = (int) (((long double)done / (long double)length) * 100);
::PostMessage(Progress, PBM_SETPOS, percent, 0);
}
}
}
close(theFile)
}
}
CRC ^= 0xFFFFFFFF;
if (IsWindow(Progress))
::PostMessage(::GetParent(Progress), WM_CRC_THREAD_DONE, (WPARAM)pCRCSt->Thread, CRC);
delete pCRCSt->pByte;
delete pCRCSt;
return CRC;
}
CRC_32::CRC_32()
{
ULONG ulPolynomial = 0x04C11DB7;
for (int i = 0; i <=0xFF; i++)
{
Table[i] = Reflect(i, 8) <<24;
for (int j = 0; j < 8; j++)
Table[i] = (Table[i] << 1) ^ (Table[i] & (1 << 31) ? ulPolynomial : 0);
Table[i] = Reflect(Table[i], 32);
}
}
ULONG CRC_32::Reflect (ULONG ref, char ch)
{
ULONG value = 0;
//swap bit 0 for bit 7, 1 for 6, 2 for 5 and so on
for (int i = 1; i < (ch + 1); i++)
{
if (ref & 1)
value |= 1 << (ch - 1);
ref >>= 1;
}
return value;
}
DWORD CRC_32::CalcCRC(LPVOID buffer, UINT size, HWND ProgressWnd)
{
if (!buffer || !size)
return 0;
if (!IsWindow(ProgressWnd))
{
DWORD CRC = 0xFFFFFFFF;
Calculate ((LPBYTE)buffer, size, CRC);
return CRC ^ 0xFFFFFFFF;
}
LPCRCStruct pCRCSt = new CRCStruct();
DWORD ThreadID;
HANDLE Handle = ::CreateThread(NULL, 0, CRC32ThreadProc, (LPVOID)pCRCSt, CREATE_SUSPENDED, &ThreadID);
if (Handle)
{
//sucessful created thread
pCRCSt->pCRC_32 = this;
pCRCSt->FileName[0] = 0;
pCRCSt->pByte = new BYTE[size];
memcpy(pCRCSt->pByte, buffer, size);
pCRCSt->size = size;
pCRCSt->hWnd = ProgressWnd;
pCRCSt->Thread = Handle;
::ResumeThread(Handle);
}
else
delete pCRCSt;
return (DWORD) Handle;
}
DWORD CRC_32::CalcCRC(LPCTSTR FileName, HWND ProgressWnd)
{
DWORD attrib = ::GetFileAttributes(FileName);
if (attrib == 0xFFFFFFFF || attrib & FILE_ATTRIBUTE_DIRECTORY)
return 0;
LPCRCStruct pCRCSt = new CRCStruct();
pCRCSt->pCRC_32 = this;
_tcsncpy(pCRCSt->FileName, FileName, MaxPath);
pCRCSt->pByte = NULL;
pCRCSt->size = 0;
pCRCSt->hWND = ProgressWnd;
pCRCSt->Thread = NULL;
if (!IsWindow(ProgressWnd))
{
return CRC32ThreadProc((LPVOID)pCRCSt);
}
DWORD ThreadID;
HANDLE Handle = ::CreateThread(NULL, 0, CRC32ThreadProc, (LPVOID)pCRCSt, CREATE_SUSPENDED, &ThreadID);
if (Handle
{
pCRCSt->Thread = Handle;
::ResumeThread(Handle);
}
else
delete pCRCSt;
return (DWORD) Handle;
}
When I run thr program, a lot errors prompt. Please help me.....
Thank you in advance!
|
|
|
|
|
This code doesn't seem to be Managed C++ - just normal Visual C++ code (so proper forum would be Visual C++ forum). But anyway...
Here is some quick notes:
1) #include "CRC2.h" --> #include "CRC32.h" ?
2) Also some other includes seem to be missing. I guess that they didn't copy to your message.
PBM_SETPOS, PBM_SETRANGE32 --> CommCtrl.h
PERCENT --> Unkonwn include
_O_RDONLY, _O_SEQUENTIAL, _O_BINARY, _SH_DENYWR --> File constants from fcntl.h
_SH_DENYWR --> Sharing constant from share.h
_tsopen --> Routine mapping from TCHAR.H
_sopen --> open file for sharing from io.h
3) LPCRCStruct --> LPCRCSTRUCT (C++ is case sensitive)
4) MaxPath --> Normally MAX_PATH
5) close(theFile) --> close(theFile);
6) _lseekie64 --> _lseeki64
7) ::PostMessage(Progress, PBM_SETPOS, PERCENT, 0); --> ::PostMessage(Progress, PBM_SETPOS, percent, 0);
8) int percent = (int) (((long double)done / (long double)length) * 100); --> You need to calculate length from somewhere.
9) pCRCSt->hWND --> pCRCSt->hWnd
10) if (Handle --> if (Handle)
11) void Calculate (const LPBYTE buffer, UINT Size, ULONG &crc); --> Where is method definition?
My include list in stdafx.h:
#include <io.h>
#include <tchar.h>
#include <windows.h>
#include <CommCtrl.h>
#include <fcntl.h>
#include <share.h>
#include <TCHAR.H>
Some includes might be unnecessary. These changes should compile files - but I don't have any idea is that doing what it is supposed to do.
There is also some ready CRC32 function implementations here in code project. For example:
CRC32: Generating a checksum for a file[^]. If you want to develope managed code, you should check out Cyclic Redundancy Check (CRC32) HashAlgorithm[^]. There is also more implementations and examples - just try search.
|
|
|
|
|
Hi,
Thanks for the reply. I had implement my codes as per your advise. Few more questions: what do you mean by:-
8) int percent = (int) (((long double)done / (long double)length) * 100); --> You need to calculate length from somewhere.
11) void Calculate (const LPBYTE buffer, UINT Size, ULONG &crc); --> Where is method definition?
(any more clear example to explain above two?)
After debugging(implemented code as follwoing), I have an error now which is as I underline in my code (prompt me erroe 2065, 'lenght': undeclared identifier, error executing cl.exe). How can I solve this?
//header file remain the same as previsous sent
#include "CRC32.h"
#include <io.h>
#include <fcntl.h>
#include <share.h>
#include <tchar.h>
#include <tchar.h>
#include <commctrl.h>
#include <windows.h>
#define BUFFERSIZE 102400
DWORD WINAPI CRC_32::CRC32ThreadProc(LPVOID lpVoid)
{
LPCRCSTRUCT pCRCSt = (LPCRCSTRUCT)lpVoid;
ULONG CRC = 0xFFFFFFFF;
HWND Progress = NULL;
if (::IsWindow(pCRCSt->hWnd))
{
Progress = pCRCSt->hWnd;
::PostMessage(Progress, PBM_SETPOS, 0,0);
::PostMessage(Progress, PBM_SETRANGE32, 0, 100);
}
if (pCRCSt->pByte)
{
for (UINT offset = 0; offset < pCRCSt->size; offset += BUFFERSIZE)
{
pCRCSt->pCRC_32->Calculate(pCRCSt->pByte + offset, (pCRCSt->size - offset > BUFFERSIZE) ? BUFFERSIZE : (pCRCSt->size - offset), CRC);
if (::IsWindow(Progress))
{
int percent = offset > pCRCSt->size ? 100 : (int)(((double) offset / (double)pCRCSt->size) * 100);
::PostMessage(Progress, PBM_SETPOS, percent, 0);
}
}
}
else if (pCRCSt->FileName)
{
LONGLONG done = 0;
UINT size = BUFFERSIZE;
BYTE buffer [BUFFERSIZE];
int theFile = _tsopen(pCRCSt->FileName, _O_RDONLY | _O_SEQUENTIAL | _O_BINARY, _SH_DENYWR);
if (theFile != -1)
{
_lseeki64 (theFile, 0L, SEEK_SET);
while (size == BUFFERSIZE)
{
size = _read(theFile, buffer, BUFFERSIZE);
if (size)
{
pCRCSt->pCRC_32->Calculate(buffer, size, CRC);
if (::IsWindow(Progress))
{
//update progcess bar
done += size;
int percent = (int) (((long double)done / (long double)length) * 100);
::PostMessage(Progress, PBM_SETPOS, percent, 0);
}
}
}
close(theFile);
}
}
CRC ^= 0xFFFFFFFF;
if (IsWindow(Progress))
::PostMessage(::GetParent(Progress), WM_CRC_THREAD_DONE, (WPARAM)pCRCSt->Thread, CRC);
delete pCRCSt->pByte;
delete pCRCSt;
return CRC;
}
CRC_32::CRC_32()
{
ULONG ulPolynomial = 0x04C11DB7;
for (int i = 0; i <=0xFF; i++)
{
Table[i] = Reflect(i, 8) <<24;
for (int j = 0; j < 8; j++)
Table[i] = (Table[i] << 1) ^ (Table[i] & (1 << 31) ? ulPolynomial : 0);
Table[i] = Reflect(Table[i], 32);
}
}
ULONG CRC_32::Reflect (ULONG ref, char ch)
{
ULONG value = 0;
//swap bit 0 for bit 7, 1 for 6, 2 for 5 and so on
for (int i = 1; i < (ch + 1); i++)
{
if (ref & 1)
value |= 1 << (ch - 1);
ref >>= 1;
}
return value;
}
DWORD CRC_32::CalcCRC(LPVOID buffer, UINT size, HWND ProgressWnd)
{
if (!buffer || !size)
return 0;
if (!IsWindow(ProgressWnd))
{
DWORD CRC = 0xFFFFFFFF;
Calculate ((LPBYTE)buffer, size, CRC);
return CRC ^ 0xFFFFFFFF;
}
LPCRCSTRUCT pCRCSt = new CRCStruct();
DWORD ThreadID;
HANDLE Handle = ::CreateThread(NULL, 0, CRC32ThreadProc, (LPVOID)pCRCSt, CREATE_SUSPENDED, &ThreadID);
if (Handle)
{
//sucessful created thread
pCRCSt->pCRC_32 = this;
pCRCSt->FileName[0] = 0;
pCRCSt->pByte = new BYTE[size];
memcpy(pCRCSt->pByte, buffer, size);
pCRCSt->size = size;
pCRCSt->hWnd = ProgressWnd;
pCRCSt->Thread = Handle;
::ResumeThread(Handle);
}
else
delete pCRCSt;
return (DWORD) Handle;
}
DWORD CRC_32::CalcCRC(LPCTSTR FileName, HWND ProgressWnd)
{
DWORD attrib = ::GetFileAttributes(FileName);
if (attrib == 0xFFFFFFFF || attrib & FILE_ATTRIBUTE_DIRECTORY)
return 0;
LPCRCSTRUCT pCRCSt = new CRCStruct();
pCRCSt->pCRC_32 = this;
_tcsncpy(pCRCSt->FileName, FileName, MAX_PATH);
pCRCSt->pByte = NULL;
pCRCSt->size = 0;
pCRCSt->hWnd = ProgressWnd;
pCRCSt->Thread = NULL;
if (!IsWindow(ProgressWnd))
{
return CRC32ThreadProc((LPVOID)pCRCSt);
}
DWORD ThreadID;
HANDLE Handle = ::CreateThread(NULL, 0, CRC32ThreadProc, (LPVOID)pCRCSt, CREATE_SUSPENDED, &ThreadID);
if (Handle)
{
pCRCSt->Thread = Handle;
::ResumeThread(Handle);
}
else
delete pCRCSt;
return (DWORD) Handle;
}
Again, thanks in advance!
|
|
|
|
|
8) You don't declare and give value for "length". This is why you get error C2065. For example:
<code>
int main()
{
int i = 100 * x;
}
</code>
To solve problem:
<code>
int main()
{
int x = 1;
int i = 100 * x;
}
</code>
Here is one possible way to calculate length.
<code>
LONGLONG done = 0;
UINT size = BUFFERSIZE;
BYTE buffer[BUFFERSIZE];
int theFile = _tsopen(pCRCSt->FileName, _O_RDONLY | _O_SEQUENTIAL | _O_BINARY, _SH_DENYWR);
if (theFile != -1)
{
long length = _lseeki64( theFile, 0L, SEEK_END );
if( length == -1L )
{
size = 0L;
switch( errno )
{
case EBADF:
break;
case EINVAL:
break;
default:
break;
}
}
if( length <= 0 )
{
length = 1L;
}
_lseeki64 (theFile, 0L, SEEK_SET);
while (size == BUFFERSIZE)
{
size = _read(theFile, buffer, BUFFERSIZE);
if (size)
{
pCRCSt->pCRC_32->Calculate(buffer, size, CRC);
if (::IsWindow(Progress))
{
done += size;
int percent = (int) (((long double)done / (long double)length) * 100);
::PostMessage(Progress, PBM_SETPOS, percent, 0);
}
}
}
close(theFile);
}
</code>
11) Your header file did have declaration for method called "Calculate", but I didn't see
any implementation for that code. (You declared identifier "Calculate" as method that doesn't return anything and takes three parameters, but you didn't provide code for that method (definition)).
I hope that you know what you are doing. There is ready CRC32 implementation for Managed code in .NET platform. And some some ready code for native C++. So you might not need to do this byself (unless you are trying to learn native C++).
|
|
|
|
|