convert wchar_t to WCHAR*
hi i'm new to all this stuff, i'm trying to write a dll and i need to convert a wchar_t to a WCHAR* , the text to go into WCHAR* must be like this
L"text in hear"
If anyone can help and/or show me whats wrong with my code thanyou
#pragma once
#include "Resource.h"
#include < stdio.h >
#include < stdlib.h >
#include < cstdlib >
#include < string.h >
#include "stdafx.h"
//using namespace std;
extern "C" __declspec( dllexport ) wchar_t sayit1( wchar_t getit );
wchar_t sayit1( wchar_t getit )
{
WCHAR *psay = getit;
ISpVoice * pVoice;
if (FAILED(::CoInitialize(NULL)))
return FALSE;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{
hr = pVoice->Speak(psay ,SPF_IS_XML, NULL);
}
::CoUninitialize();
return NULL;
}
hope i put this post in the rite place =P
[Edited by - Veeman on February 28, 2010 2:10:41 PM]
I'd suggest reading up about how strings are stored. You seem to be trying to treat a single character as a string. If you wanted to get a pointer to a single char or wchar_t, well... Grab it's address!
If you are trying to pass a string, try the following for your function header.
wchar_t wc = L'P';wchar_t* pWC = &wc;
If you are trying to pass a string, try the following for your function header.
wchar_t sayit1( const wchar_t * getit ){// You shouldn't need this// WCHAR *psay = getit;...
thanx zyro for the help but i tryed and tryed and it would compile and run but no sound came out, i dunno how i'm going to get it working =(
mabe i'll have to learn pointers
well i'm going to read up and have ago with pointers tomorrow
if any one can help in the meantime please reply
#pragma once
#include "Resource.h"
#include < stdio.h >
#include < stdlib.h >
#include < cstdlib >
#include < string.h >
#include "stdafx.h"
extern "C" __declspec( dllexport ) wchar_t sayit1( const wchar_t * getit );
wchar_t sayit1( const wchar_t * getit )
{
ISpVoice * pVoice;
if (FAILED(::CoInitialize(NULL)))
return FALSE;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{
hr = pVoice->Speak(getit ,SPF_IS_XML, NULL );
}
::CoUninitialize();
return NULL;
}
mabe i'll have to learn pointers
well i'm going to read up and have ago with pointers tomorrow
if any one can help in the meantime please reply
#pragma once
#include "Resource.h"
#include < stdio.h >
#include < stdlib.h >
#include < cstdlib >
#include < string.h >
#include "stdafx.h"
extern "C" __declspec( dllexport ) wchar_t sayit1( const wchar_t * getit );
wchar_t sayit1( const wchar_t * getit )
{
ISpVoice * pVoice;
if (FAILED(::CoInitialize(NULL)))
return FALSE;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{
hr = pVoice->Speak(getit ,SPF_IS_XML, NULL );
}
::CoUninitialize();
return NULL;
}
Quote:Original post by VeemanA very good idea. It is perhaps almost as important as knowing how to add, when it comes to C & C++ programming.
mabe i'll have to learn pointers
well i'm going to read up and have ago with pointers tomorrow
Feel free to ask questions about them here if you need to.
sorry i havent been back here for a while got people in rewiring the house and a new bath room and kitchen being put in =S
anyhow i call the function in dark basic at the moment it just says 'E' but heres the code anyway
edit:-
just bin trying it out and it only says the last letter in the string (a$)
`arrays & vars
a$="hello there"
dim organizer(365,1000,15)
`load DLL's
load dll "sayit.dll",1
`main
do
print CALL DLL (1, "sayit1",a$)
suspend for key
loop
[Edited by - Veeman on March 8, 2010 8:44:07 AM]
anyhow i call the function in dark basic at the moment it just says 'E' but heres the code anyway
edit:-
just bin trying it out and it only says the last letter in the string (a$)
`arrays & vars
a$="hello there"
dim organizer(365,1000,15)
`load DLL's
load dll "sayit.dll",1
`main
do
print CALL DLL (1, "sayit1",a$)
suspend for key
loop
[Edited by - Veeman on March 8, 2010 8:44:07 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement