|
i replaced _MBCS with _UNICODE ,UNICODE.
These two functions are failing to encrypt and decrypt even though THCAR ,_tcslen , etc used, thats why i posted a question here...
|
|
|
|
|
No no, I didn't mean that. There are plenty of external dependencies. For instance, the following: CryptAcquireContext , CryptCreateHash , CryptHashData , etc.
So I do not have a clue of what is going on. Did you try debugging to analyse what is going on in the program?
PS: Replacing _MBCS with _UNICODE is sufficient. _UNICODE implicitly defines UNICODE and so you do not need to define UNICODE separately.
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
yeah i debugged
memcpy(pbBuffer, szPassword, dwLength);
if (CryptEncrypt(hKey, 0, TRUE, 0, pbBuffer, &dwLength, dwLength))
{
memcpy(szEncryptPwd, pbBuffer, dwLength);
may be CryptEncrypt function or CryptDeriveKey these two functions
and/or memcpy() function and length these are the main concerns
|
|
|
|
|
Use wmemcpy while working with Unicode strings. memcpy is for working with non-unicode strings. Sorry that I missed it earlier.
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
You'll need to go through the code and make SURE that all your "dwLength" (and similar) variables
are both initialized and used properly.
The Cryptxxx() APIs only deal in bytes - Unicode doesn't change that. Make sure you are using
counts calculated in TCHARs or in bytes where applicable.
wmemcpy doesn't apply here either
Mark
|
|
|
|
|
How is this going to work:
dwLength = sizeof(TCHAR)*_tcslen(szEncryptPwd);
If szEncryptPwd is encrypted there's not necessarily an ASCIIZ at the end so _tcslen()
won't work. You need a way to store the encrypted length somewhere or use a pre-defined length.
*EDIT* The encrypt side looks ok but the decrypt isn't going to work as coded.
Also, not all encryption algorithms produce the same number of encrypted bytes as unencrypted
source bytes, but you've assumed that in your encryption function. Be careful
You can check the size required with an extra call to CryptEncrypt() with the pbData param set to
NULL.
Mark
|
|
|
|
|
There's more
BOOL EncryptString(LPTSTR szPassword,LPTSTR szEncryptPwd,LPTSTR szKey)
In addition to my last reply...
szEncryptPwd should be a BYTE *, not a TCHAR *. The bytes are encrypted so can no longer be used
as a character string. You could maybe append a WORD value to the beginning of the bufer
to store the encrypted length for use in the decrypt function (just one scheme).
Mark
|
|
|
|
|
I want to safely remove the usb drive programatically.How can i do this.
Thanks.
|
|
|
|
|
|
Okay... this question feels out of place in this forum, but it doesn't fit in OS/SysAdmin as that is more of the usage side - not the programming side. Given my driver is in C++, I figure this is as good a place as any.
That out of the way, I found a bug (handle leak) in cmd.exe:
I'm writing a device driver that I want to be able to write stuff to via the command prompt redirection. For example, typing
echo Hello there > \\.\MyDevice
Should send the string "Hello there" to the MyDevice device.
Unfortunately it does not work. Cmd opens the handle to my device, but never writes to it or closes it! So until I exit cmd, my driver cannot be unloaded.
Some debugging indicates that cmd opens my device with CreateFile, which succeeds, then calls GetFileType, and since it is not a file or network file, it cancels the redirection operation, forgetting to close the original handle.
So now for the real question:
Does anybody happen to know how GetFileType is implemented in kernel mode (ie. if there's a field of the FILE_OBJECT I can set to get GetFileType to work properly? Or is there any way to register something like lpt1 which is a device that cmd can write to?
Thanks,
Mike
|
|
|
|
|
Hi i am writing a dll to proses msg files (sender,subject, etc). I managed to get right down to the IMessage Properties but i can't figure out how to return the value from my DLL.. This is my First c++ project (I know right in to the deep end MAPI and all, but it is better than MsgBox("hello world") )
Note the return value neads to be VB safe
CODE (See bit commented STUCK HERE)
/--------------------------------------------------------------------------------
#include <malloc.h>
#include "stdafx.h"
#include <mapi.h>
#include <mapix.h>
#include <mapiutil.h>
#include <ole2.h>
#include <imessage.h>
#define TEST_EXPORTS
#include "SSFILEDLL.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
SSFILEDLL_API BSTR __stdcall Test()
{
HRESULT hr;
BSTR Message;
hr = MAPIInitialize(NULL);
if (FAILED(hr))
return "False";
hr = OleInitialize(NULL);
if (FAILED(hr))
return "False";
//get storage from msg file
LPSTORAGE pStorage= NULL;
hr = StgOpenStorage(L"C:\\Test\\2005-1~4.MSG",
NULL,
STGM_READWRITE | STGM_TRANSACTED | STGM_SHARE_EXCLUSIVE,
NULL,
0,
&pStorage);
if (FAILED(hr))
return "False";
//Alloc memory
LPMALLOC pMalloc = MAPIGetDefaultMalloc();
//open a IMessage session
LPMSGSESS pMsgSession = NULL;
hr = OpenIMsgSession (pMalloc, 0 , &pMsgSession);
if (FAILED(hr))
return "False";
//open an IMessage on the IStorage object
LPMESSAGE pSourceMsg = NULL;
hr = OpenIMsgOnIStg(pMsgSession,
MAPIAllocateBuffer,
MAPIAllocateMore,
MAPIFreeBuffer,
pMalloc,
NULL,
pStorage,
NULL,
0,0,&pSourceMsg);
if (FAILED(hr))
return "False";
//ok can we get to the properties
SizedSPropTagArray(1, _attrs_) =
{
1,
{
PR_SUBJECT
}
};
LPSPropAttrArray lpAttributes = NULL;
hr = GetAttribIMsgOnIStg(
pSourceMsg,
(LPSPropTagArray)&_attrs_,
&lpAttributes
);
if (FAILED(hr))
{
return "False";
}
else
{
//STUCK HERE
//lpAttributes[0].cValues; should be the subject
//so how do i convert this to a BSTR (the way I have retrned data in the Past)
return Message;
MAPIFreeBuffer(lpAttributes);
}
//------------------------------------
if (pSourceMsg)
pSourceMsg->Release();
if (pMsgSession)
CloseIMsgSession(pMsgSession);
if (pStorage)
pStorage->Release();
MAPIUninitialize();
}
/--------------------------------------------------------------------------------
Many thnaks
|
|
|
|
|
Calvin Streeting wrote: //STUCK HERE
//lpAttributes[0].cValues; should be the subject
//so how do i convert this to a BSTR (the way I have retrned data in the Past)
Do you want to return lpAttributes[0].cValues ? But it is UINT . Do you want to convert it to BSTR ?
Again some advice, returning from this point will cause suppressing clean up routine you have written below this code.
|
|
|
|
|
many thanks
I did some more reading on GetAttribIMsgOnIStg and have found that it only returns the count and if the attribute is pressent... so i am not as far as i thought... i need to look into to get the actuall data..so i looked on msdn and found that i need to read up on these
typedef struct _SPropValue
{
ULONG ulPropTag;
ULONG dwAlignPad;
union _PV Value;
} SPropValue, FAR *LPSPropValue;
HRESULT GetProps(
LPSPropTagArray lpPropTagArray, ULONG ulFlags, ULONG FAR * lpcValues, LPSPropValue FAR * lppPropArray );
which regard to "returning from this point will cause suppressing clean up routine you have written below this code" I agree,but this is only test code to see if i can get to the data and will latter be split in to different function
OpenFile()
Getdata() //to be repeated for all data requerd
CloseFile() //where i clean up
Once Again Many Thanks
|
|
|
|
|
Using visual 2005 and work with C++.
The error that i getting in the last line of the code is
C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject'
and the class code is
#pragma once<br />
<br />
#include "stdafx.h"<br />
<br />
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#endif<br />
<br />
<br />
<br />
class CMyFile : public CObject<br />
{<br />
DECLARE_SERIAL(CMyFile);<br />
<br />
public:<br />
CMyFile(void);<br />
virtual ~CMyFile(void);<br />
virtual void Serialize(CArchive &ar);<br />
virtual CMyFile& operator=(CMyFile &MyFile);<br />
<br />
private:<br />
CString m_sPath;<br />
CString m_sData;<br />
<br />
public:<br />
CString GetPath(){return m_sPath;};<br />
void SetPath(CString sPath){m_sPath = sPath;};<br />
<br />
CString GetData(){return m_sData;};<br />
void SetData(CString sData){m_sData = sData;}; <br />
};
Please help me - i dont know what is wrong
Thanks.
|
|
|
|
|
A derived class can not access private members inherited from its base class(es).
Steve
|
|
|
|
|
To add to previous reply. Probably, you are doing some thing wrong while using this class,or implementing this class.
|
|
|
|
|
I dont have any access to private member of the class that i inheritor from.
I inheritor from class CObject because i need to use Serialize.
This is my cpp fine code ( the h file code i add already )
#include "stdAfx.h"<br />
#include "MyFile.h"<br />
<br />
IMPLEMENT_SERIAL(CMyFile, CObject, 1);<br />
<br />
CMyFile::CMyFile(void)<br />
{<br />
}<br />
<br />
CMyFile::~CMyFile(void)<br />
{<br />
}<br />
<br />
void CMyFile::operator=(CMyFile& MyFile)<br />
{<br />
m_sData = MyFile.GetData();<br />
m_sPath = MyFile.GetPath();<br />
}<br />
<br />
void CMyFile::Serialize(CArchive &ar)<br />
{<br />
CObject::Serialize(ar);<br />
<br />
if(ar.IsStoring())<br />
{<br />
ar << m_sPath << m_sData;<br />
}<br />
else<br />
{<br />
ar >> m_sPath >> m_sData;<br />
}<br />
}
|
|
|
|
|
At which line exactly , it is showing error ?
|
|
|
|
|
In the last line of the h file.
|
|
|
|
|
Strange !
Can you mail me your dummy application having this error.
|
|
|
|
|
How can i send it ?
What your mail ?
|
|
|
|
|
prasad_s#mail_com
(replace '_' with '.' and '#' with '@'.)
|
|
|
|
|
I have one function to which I want to pass a pointer to a VARIANT:
THE FUNCTION
long CDlg::Add(int i, VARIANT *varVal)<br />
{<br />
varVal->bstrVal = m_cslist[i].AllocSysString();<br />
return m_Object.function(m_cslist[i], &varVal);<br />
}
FROM WHERE I CALL IT
VARIANT varVal;<br />
varVal.vt = VT_BSTR;<br />
for (int i := 0; i < 100; i++)<br />
{<br />
lErr = Add(i, &varVal);<br />
}
Well, doing this makes this to happen:
'function' : cannot convert parameter 2 from 'struct tagVARIANT ** ' to 'const struct tagVARIANT &'
I'd like to do it in this way, I'm using always the same variant as an auxiliary value, and some parameters are predefined (varVal.vt = VT_BSTR; ) for all the times I want to use it.
I believe that passing the entire value for several calls will slow down the entire process...
Thank you in advance.
|
|
|
|
|
Are you calling Add from within CDlg ?
(1) If the answer is YES, then the compiler cannot complain!
(2) If the answer is NO, then you're doing the wrong call (and the compiler, again cannot show the error posted).
Hence, sure that have you got that error?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Yes, I have the error, the solution is on the next answer.
Thank you for your feedback!
|
|
|
|
|