thiel
asked on
gina
I'm developing a security system using smart cards. I'm also trying to use these cards to login to Windows NT, so I'm creating a custom GINA library.
I'm working with the original msgina.dll but I have a problem when reading the characters from the smart card because these are stored in ASCII code and GINA is expecting an unsigned short.
I was wondering if you could help me solve this problem. Thank you.
Thiel Fischer
thiel@telcom.net
I'm working with the original msgina.dll but I have a problem when reading the characters from the smart card because these are stored in ASCII code and GINA is expecting an unsigned short.
I was wondering if you could help me solve this problem. Thank you.
Thiel Fischer
thiel@telcom.net
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Before I do that, please tell me why you need to do it. If you choose to build this applications as a pure UNICODE project, there should be no need for this.
In an MFC or ATL app, you can include afxpriv.h which include a whole set of character conversion macros. The A2W macro will convert from char to wchar_t.
Otherwise, there is the MultiByteToWideChar function.
In an MFC or ATL app, you can include afxpriv.h which include a whole set of character conversion macros. The A2W macro will convert from char to wchar_t.
Otherwise, there is the MultiByteToWideChar function.
ASKER
I'm using char types beacuse it is what I receive from the reader and also the Gina project is already builded.
I tried the following
WideCharToMultiByte(CP_ACP ,0,pMini-> pszUsernam e,-1,caden a,sizeof(c adena),NUL L,NULL);
But when Gina runs returns the following error:
Initialization of the dynamic link library c:\winnt\system32\inetmib1 .dll failed. The process is terminatig abnormally.
Then the Winlogon aplication ends and the system automaticaly reboot the machine.
I tried the following
WideCharToMultiByte(CP_ACP
But when Gina runs returns the following error:
Initialization of the dynamic link library c:\winnt\system32\inetmib1
Then the Winlogon aplication ends and the system automaticaly reboot the machine.
ASKER
Also I tried to use the following convertions
AsciiToUnicode(pMini->pszU sername,ca dena);
void
AsciiToUnicode(PWCHAR dst, char *src)
{
while (*src)
*dst++ = (WCHAR)*src++;
*dst = 0;
}
cadena is a char[16] variable
but the winlogon return the following error:
The Instruction at "0x10001a43" referenced memory at "0x007300069". The memory could not be "written".
AsciiToUnicode(pMini->pszU
void
AsciiToUnicode(PWCHAR dst, char *src)
{
while (*src)
*dst++ = (WCHAR)*src++;
*dst = 0;
}
cadena is a char[16] variable
but the winlogon return the following error:
The Instruction at "0x10001a43" referenced memory at "0x007300069". The memory could not be "written".
Initialization of the dynamic link library c:\winnt\system32\inetmib1 .dll failed
This has nothing that I can think of to do with MultiByteToWideChar().
You have:
WideCharToMultiByte(CP_ACP ,0,pMini-> pszUsernam e,-1,caden a,sizeof(c adena),NUL L,NULL);
the DESTINATION of the conversion operation is NULL. That's not good...
You also have 8 arguments to this function, I only count 6:
int MultiByteToWideChar(
UINT CodePage, // code page
DWORD dwFlags, // character-type options
LPCSTR lpMultiByteStr, // string to map
int cbMultiByte, // number of bytes in string
LPWSTR lpWideCharStr, // wide-character buffer
int cchWideChar // size of buffer
);
Here is a sample that I put together using this function as well as a manual way similar to what you've done:
#include "stdafx.h"
#include "Ansi2Unicode.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CWinApp theApp;
using namespace std;
BOOL AnsiToUnicode(wchar_t *dst, char *src)
{
if(dst == NULL || src == NULL){
return FALSE;
}
memset(dst, 0, (strlen(src)+1) * 2);
while(*src){
*dst = (wchar_t)*src;
dst++;
src++;
}
return TRUE;
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
// The string to convert
char *lpszSource = "This is only a test";
// Destination for MultiByteToWideChar
wchar_t *wszDest1 = new wchar_t[(strlen(lpszSource )+1) * 2];
// Destination for AnsiToUnicode function
wchar_t *wszDest2 = new wchar_t[(strlen(lpszSource )+1) * 2];
// Have Windows convert it.
MultiByteToWideChar(CP_ACP , 0, lpszSource, -1, wszDest1, (strlen(lpszSource)+1) * 2);
// Do it the hard way.
if(AnsiToUnicode(wszDest2, lpszSource)){
cerr << "OK" << endl;
}
else{
cerr << "Error" << endl;
}
// See if they are the same
if(wcscmp(wszDest1, wszDest2) == 0){
cerr << "Same" << endl;
}
else{
cerr << "Different" << endl;
}
delete [] wszDest1;
delete [] wszDest2;
return 0;
}
This has nothing that I can think of to do with MultiByteToWideChar().
You have:
WideCharToMultiByte(CP_ACP
the DESTINATION of the conversion operation is NULL. That's not good...
You also have 8 arguments to this function, I only count 6:
int MultiByteToWideChar(
UINT CodePage, // code page
DWORD dwFlags, // character-type options
LPCSTR lpMultiByteStr, // string to map
int cbMultiByte, // number of bytes in string
LPWSTR lpWideCharStr, // wide-character buffer
int cchWideChar // size of buffer
);
Here is a sample that I put together using this function as well as a manual way similar to what you've done:
#include "stdafx.h"
#include "Ansi2Unicode.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CWinApp theApp;
using namespace std;
BOOL AnsiToUnicode(wchar_t *dst, char *src)
{
if(dst == NULL || src == NULL){
return FALSE;
}
memset(dst, 0, (strlen(src)+1) * 2);
while(*src){
*dst = (wchar_t)*src;
dst++;
src++;
}
return TRUE;
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
// The string to convert
char *lpszSource = "This is only a test";
// Destination for MultiByteToWideChar
wchar_t *wszDest1 = new wchar_t[(strlen(lpszSource
// Destination for AnsiToUnicode function
wchar_t *wszDest2 = new wchar_t[(strlen(lpszSource
// Have Windows convert it.
MultiByteToWideChar(CP_ACP
// Do it the hard way.
if(AnsiToUnicode(wszDest2,
cerr << "OK" << endl;
}
else{
cerr << "Error" << endl;
}
// See if they are the same
if(wcscmp(wszDest1, wszDest2) == 0){
cerr << "Same" << endl;
}
else{
cerr << "Different" << endl;
}
delete [] wszDest1;
delete [] wszDest2;
return 0;
}
Oops! I'm sorry, you're using WideCharToMultiByte. This converts a UNICODE to ASCII.
You want to call MultiByteToWideChar.
That is what I said, isn't it????
Yes, I said:
>>Otherwise, there is the MultiByteToWideChar function.
You want to call MultiByteToWideChar.
That is what I said, isn't it????
Yes, I said:
>>Otherwise, there is the MultiByteToWideChar function.
ASKER