Jump to content
Xtreme .Net Talk

cant call global function out of class ???


Recommended Posts

Posted

Hi.

I downloaded Speech SDK from MS site just to try all that cool stuff you can do with it :). The project is a Managed Application. I use garbage collector public class to create a form, add event handler. I cant set the global function as an event handler so i create another function that points to the global function. The function is global because it doesnt seem to do what its supposed to if its in the form class. Its all good, no errors during debugging and when i try to make the app speak a sentence after clicking a button it doesnt do anything. The only way it works is if i put the speaking in main function but that sucks cause cant do much with it if its in main cause its gonna start by tself.

 

Here is some code:

 

My button event handler:

btnSpeak->Click += new EventHandler(this,&Speaker::CheckText);

 

My function that initializes the function that will do the speaking:

void CheckText(Object* pSender, EventArgs* pArgs)
{
SpeakText();
}

 

And my speaking function (this is the global one):

int SpeakText()
{
ISpVoice * pVoice = NULL;

   if (FAILED(::CoInitialize(NULL)))
       return FALSE;

   HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
   if( SUCCEEDED( hr ) )
   {
	hr = pVoice->Speak(L"SPEAK GODDAMIT!!!!!!", SPF_IS_XML, NULL );
       pVoice->Release();
       pVoice = NULL;
   }
   ::CoUninitialize();
   return TRUE;
}

 

ANY help would be appreciated.

 

BTW. Im the first one to post in VC++ forum :D :D :)

Posted

Hi mutant

 

I'm not a c++ syntax expert (In fact, I never coded c++ in my live), but it's close enough to c#, so here goes..

 

Just two questions...

 

1) When did you hook up your button event handler (e.g. from load... windows component code area...etc) and,

2) Did you try to debug the SpeakText function? Isn't it failing on your initializing condition:

 

if (FAILED(::CoInitialize(NULL)))

return FALSE;

 

...

Howzit??
Posted

My form class is called from main function which is run on the prog start. My button handler is hooked up when i declare the button in the form class and set up all the location, size of the button, its text, and all that. Heres the code:

 

This the routine that sets up the button on the form

 

void SetUpControls()
{
	btnSpeak = new Button();
	btnSpeak->Text = S"Speak";
	btnSpeak->Size = System::Drawing::Size(100,20);
	btnSpeak->Location = Point(10,35);
	btnSpeak->Click += new EventHandler(this,&Speaker::CheckText);
	Controls->Add(btnSpeak);

	txtText = new TextBox();
	txtText->Size = System::Drawing::Size(100,100);
	txtText->Location = Point(10,10);
	Controls->Add(txtText);
}

 

As to the question no.2. The function works if i put the code in the main() function without calling anything cause code is already there. But i want the user to be able to enter what he wants to say in the textbox.

Posted

Sorry man.... Tried to help, failed :(

 

The code seems to be fine, must be to do with the Speech SDK or some other hidden reason.

 

No C++.Net experts out there? :confused:

 

Is C++ going to be a second J#? ;)

 

Cheers

Howzit??
Posted

Coding forms by hand is a lot of fun and sometimes frustration ;)

Form designers are gonna kill good ol' C++ :) :-\ :rolleyes:

  • *Experts*
Posted

Off-topic

 

If MFC didn't kill C++, .NET surely won't :)

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...