• Welcome to Valhalla Legends Archive.
 

Console application

Started by brew, April 13, 2007, 08:29 PM

Previous topic - Next topic

brew

So i made this console application and in order for the program to stay active, i have to run a constant loop.
this is VERY cpu consuming, and when I tried to connect to bnet with it, it took about 7-8 seconds. (if i commented out the loop it would connect much faster, but not work after that.)

Private Const STD_INPUT_HANDLE = -10&
Private Const STD_OUTPUT_HANDLE = -11&
Private Const STD_ERROR_HANDLE = -12&

Sub Main()
    Show
    Do
        DoEvents
        Select Case ReadText
            Case "/exit": Hide
            Case "/connect"
                frmMain.WS.Close
                frmMain.WS.Connect "213.248.106.200", 6112
                AddChat vbForeYellow, "[BNET] Connecting..."
        End Select
        DoEvents
    Loop
End Sub

Public Sub Show()
    AllocConsole
    SetConsoleTitle "Console Test"
    hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)
    hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
    hConsoleErr = GetStdHandle(STD_ERROR_HANDLE)
End Sub

so on...

Anyone got any ideas
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P


Barabajagal

Don't use VB for console apps?

brew

<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

warz

but... what you're trying to write is better suited for a different language

brew

acually you're right... the past two topics i've posted here pertains to things almost unheard of in vb6 and easy as hell in c/c++, but i still love vb if vb was a person i'd hug it
Uhh and btw i believe the way consoles in C work the same way, except they have a break(); (or something) at the end of execution, so it doesn't exit until it receives input (a key press) So i think the entire thread is paused in C, too. You just don't notice it. (correct me if im completely wrong) Yeah, using a console was a bad idea. Anyone know where I can get the "raster fonts" that console uses?
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

l2k-Shadow

instead, you could use CreateWindow() and code the application window, then implement a callback function
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

brew

Quote from: l2k-Shadow on April 13, 2007, 09:47 PM
instead, you could use CreateWindow() and code the application window, then implement a callback function
I acually tried that-- by using form_Load on startup, then calling sub main(). Now it no longer exits immediately, but the console window that is "spawned" is now "inactive" (no input/output). It seems like I no longer have a handle on that console window (but i know i do, i would have to. I don't call freeconsole() until hide, which is only called upon exit command)
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

l2k-Shadow

is a console application necessary, or are you just interested in not using forms? you can simply call CreateWindow() and RegisterClass() to make a window and then work with calls from the callback function. But if you don't want to do that, why don't you just implement like a Sleep(1) call as to not get owned by the intensity of an infinite loop.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Hell-Lord

One thing is to remove DoEvents.

warz

one thing one thing one thing, boo hoo

Hell-Lord


brew

<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

brew

#13
Quote from: l2k-Shadow on April 13, 2007, 11:23 PM
is a console application necessary, or are you just interested in not using forms? you can simply call CreateWindow() and RegisterClass() to make a window and then work with calls from the callback function. But if you don't want to do that, why don't you just implement like a Sleep(1) call as to not get owned by the intensity of an infinite loop.
Wow, i just tried the sleep api like you said and it worked absolutely perfect. (although i'm not exactly sure why/how) Thanks, shadow.

Edit*
It doesn't work after you enter text 3 times. And if I use the loop way, which is guarenteed to work, it doesn't connect. What gives -_-
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

MyndFyre

Quote from: brew on April 13, 2007, 08:36 PM
but... i like vb

VB.NET.  Console.ReadLine() blocks the thread while in a loop preventing massive CPU usage.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.