| Strange Error - WebClient DownloadData |
|
 |
Index ‹ Visual Studio ‹ Visual Basic [VB]
|
- Previous
- 1
- MFC >> Text file IOI have a class that inputs data from a text file. The files can be very
large, and I'd like to display a progress bar to the user. Of course, to
determine this I need to know the total number of lines in the file. What's
the most efficient (i.e. fastest) way to get it? Right now I use brute
force: I read through the entire file, counting the lines but not processing
the data (code below). Then I reset the ifstream to prepare for reading the
data. Is there a better way?
Thanks,
Chip
// Construct ifstrem object for file input
ifstream File(Filename, ios::nocreate);
********
// Count total lines in file
streampos StartPos = File.tellg(); // Get file start position
FileLines = 0;
while(!File.eof())
{
File.ignore(1000, '\n'); // Get/ignore line
FileLines++;
}
// Prepare File for reading/processing
File.seekg(StartPos); // Return istream ptr to start position
File.clear(); // Reset eof bit
TRACE("File has %i lines\n", FileLines);
******
// Read data...
- 2
- Mcse >> The Practice Test Package Development: A New Service on the Certification Market01/19/2005 - Visual CertExam Software has launched the practice test
package development service to making it easier and less expensive for
companies to create practice tests.
The practice test package development service will provide you with a
universal solution for easy development and distribution of your own
practice exams.
The practice test package is a standalone setup program (setup.exe)
that contains a question bank and the application for taking tests.
These packages are very similar to Transcender and Self Test Software
practice tests.
Using this service sets you free from having to develop your own
software and thus makes the process of development your own practice
exams simpler and less expensive.
A practice test package includes the following features:
- The question bank and the application for taking test are
distributed as a single setup.exe file. This means that your users
don't need to buy and install any additional software in order to take
your tests.
- If you are a small company and have no an opportunity to develop
your own test engine, you can obtain the professional solution for
practice test delivery for a low cost.
- You can freely update a question bank in order to keep your test
actual.
- Each practice test package has a build-in activation mechanism.
For more information, see http://www.visualcertexam.com/service.html
- 3
- 4
- Visual Basic [VB] >> Adding the rebooting code to the setup project !Hi EveryBody:
Is there any way to add the rebooting code to the user interface of the setup project in VB.net ? if the answer is yes,how can I do it ?
but if the answer is no, Is there any way to add dialog that I made by myself which consist of the rebooting code to the user inteface of the setup project ? if the answer is yes, how can I do it ?
But if the answer is now, Is there any way to let my setup project rebooting after the installation is done?
any help will be appreciated.
al-ahmadi
- 5
- Visual Basic [VB] >> invalid cast prob with oleDBdataReader...
Dim rdr As OleDbDataReader = cmd.ExecuteReader
If rdr.GetString(1).ToString.Length > 0 Then
Console.WriteLine(rdr.GetString(1).ToString)
End If
The field is in an MS Access table that rdr is reading and
is a text field. I am getting an invalid cast error when
the field is null/empty.
I have tried If Not IsDBNull(rdr.GetString(1).ToString)...
still same problem. How can I trap if the field is null?
Thanks
- 6
- VB Scripts >> TOP SECRET MY MOM NEVER TOLD ME!!Discovers the "Secret of making huge money" in just few weeks....
You shall be amazed that how easy 1 can make money on internet just for doing 1 time work..[I GUREENTED U CAN TOO MAKE BIG$$ WITH THIS PROGRAM]........
[Use IE if can't view the site]
http://mysiteinc.com/gohar/index.html
- 7
- MFC >> how passwords should be stored under windowsHi, I have a project which needs me to store passwords
under windows, I just wondering how those passwords should
be stored. For example, if I store in the registry, is
there any encription tool I can use so that only my
program can read and write it?
- 8
- VB Scripts >> How to use ADO.NET in vbs file called from command line?I'm trying to run some ADO.NET code in a vbs file that is called from the
command line as follows:
C:\CScript MyFile.vbs
but I get a compilation error, expected end of statement. The sample code
below is where I'm trying to just open/close a connection..What do I have to
do to use the .NET framework?
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Dim sqlConnection As SqlConnection = New SqlConnection()
sqlConnection.ConnectionString =
"SERVER=dbserver;DATABASE=mydb;UID=username;PWD=password"
sqlConnection.Open()
sqlConnection.Close()
- 9
- Visual Basic [VB] >> MarshalingGuys, please help. I am trying to make this work from at least 4 months.
I am new to programming and some things are difficult to me, but I really
need to make my project work.
I can't find anything helpfull in internet for 4 months ;-( .
Please someone who is more expirenced help me.
I am trying to use the Terminal Server APIs
There is as an API function WTSEnumerateSessions, which returns a
WTS_SESSION_INFO custom structure n times.
Actually it returns pointer to it.
I just can't get it working in VB .NET
While searching through MSDN I've found something, but I need an opinion
from someone more experienced.
The text is:
======
Formatted Non-Blittable Classes
Formatted non-blittable classes have fixed layout (formatted) but the data
representation is different in managed and unmanaged memory. The data can
require transformation under the following conditions:
If a non-blittable class is marshaled by value, the callee receives a
pointer to a copy of the data structure.
If a non-blittable class is marshaled by reference, the callee receives
a pointer to a pointer to a copy of the data structure.
If the InAttribute attribute is set, this copy is always initialized
with the instance's state, marshaling as necessary.
If the OutAttribute attribute is set, the state is always copied back to
the instance on return, marshaling as necessary.
If both InAttribute and OutAttribute are set, both copies are required.
If either attribute is omitted, the marshaler can optimize by eliminating
either copy.
Found at:
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconconsumingunmanageddllfunctions.asp)
======
According to this the date returned from WTSEnumerateSessions function is a
pointer to a pointer a copy of the data structure.
Or I am wrong?
If I am right, how to get this second pointer from VB .NET?
Here are the API Function and structure, by definition and how I've defined
them in my app
API
=====
WTS_SESSION_INFO
The WTS_SESSION_INFO structure contains information about a client session
on a terminal server.
typedef struct _WTS_SESSION_INFO { DWORD SessionId; LPTSTR
pWinStationName; WTS_CONNECTSTATE_CLASS State;
} WTS_SESSION_INFO, *PWTS_SESSION_INFO;
WTSEnumerateSessions
The WTSEnumerateSessions function retrieves a list of sessions on a
specified terminal server.
BOOL WTSEnumerateSessions(
HANDLE hServer,
DWORD Reserved,
DWORD Version,
PWTS_SESSION_INFO* ppSessionInfo,
DWORD* pCount
);
=====
And in my code
====
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Private Structure WTS_SESSION_INFO
Dim SessionID As Int32 'DWORD integer
Dim pWinStationName As String ' integer LPTSTR - Pointer to a
null-terminated string containing the name of the WinStation for this
session
Dim State As WTS_CONNECTSTATE_CLASS
End Structure
<DllImport("wtsapi32.dll", _
bestfitmapping:=True, _
CallingConvention:=CallingConvention.StdCall, _
CharSet:=CharSet.Auto, _
EntryPoint:="WTSEnumerateSessions", _
SetLastError:=True, _
ThrowOnUnmappableChar:=True)> _
Private Shared Function WTSEnumerateSessions2( _
ByVal hServer As IntPtr, _
<MarshalAs(UnmanagedType.U4)> _
ByVal Reserved As Int32, _
<MarshalAs(UnmanagedType.U4)> _
ByVal Vesrion As Int32, _
ByRef ppSessionInfo As IntPtr, _
<MarshalAs(UnmanagedType.U4)> _
ByRef pCount As Int32) As Int32
End Function
TIA
- 10
- Mcse >> ATTN: ConsultantConsultant, I suggest you take a look at
http://www.microsoft.com/communities/conduct/default.mspx
and acquaint yourself with the Chat code of conduct,
especially rule 1:
"Please treat all other online participants with respect
and do not use Microsoft Community Chats to threaten,
harass, stalk, or abuse other users."
Brain Boon
- 11
- Visual Basic >> IIS permissionsSorry if this is the wrong newsgroup for this but I don't know a better one
and I figure a lot of people in this one might have some experience in this.
Basically I am trying to create a simple ASP application that will
instantiate excel, export a chart to a gif, and then write an img src tag
with the name of that gif. I've tried it as a Visual Basic IIS application
and a normal ASP application using Visual Interdev. With the Visual Basic
IIS application, it works fine in debug mode. But deploying it is the real
nightmare. I've tried creating a virtual directory from within IIS and
setting the permissions to include Write, and copying the resulting .ASP
file that VB creates to that directory. I get Application defined or object
defined error - Excel couldn't save the file. In fact it won't even do
anything that involves writing to a file.
I get a similar sort of error when trying to do it from Visual Interdev.
I can't see what I'm doing wrong - can anyone point me in the right
direction?
I've tried using the P&D wizard to publish it to the server but it gave me a
'no post info file found on server' message. I'm running XP pro
(workstation).
- 12
- MFC >> Screen captures of windows other than one belonging to app.Is there an easy way to perform a screen capture of a window that does
not belong to the application doing the screenshot? I know you can
capture the entire screen, but I would like to capture selected windows.
I'm guessing that it's possible if the capturing app can get hold of the
DC of the target window, but I'm not sure how you do that. Paint
programs seem to be able to do this so I guess it's possible.
(BTW: I'm using VC6 with DirectX 8.0 SDK installed.)
- 13
- MFC >> LVS_OWNERDATA and NM_CUSTOMDRAW with CListCtrl == slow?Forgive me if this is a near duplicate post... anyway, I'm trying to use
NM_CUSTOMDRAW to draw all the items manually in a virtual CListCtrl (a list
control with LVS_OWNERDATA). The problem is that my method is very slow and
sluggish feeling compared to the way windows does it, and I don't know why.
Keeping in mind that NM_CUSTOMDRAW is only fired once per item, due to the
LVS_OWERDATA style, rather than once per sub item, perhaps someone can
explain to me what I'm doing wrong? Heres the code:
void CMusikPlaylistCtrl::OnLvnGetdispinfo(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
// NM_CUSTOMDRAW will take care of drawing
*pResult = 0;
}
void CMusikPlaylistCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
*pResult = CDRF_DODEFAULT;
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
*pResult = CDRF_NOTIFYITEMDRAW;
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
int iRow = (int)pLVCD->nmcd.dwItemSpec;
CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
CRect item_rect;
GetItemRect( iRow, &item_rect, LVIR_BOUNDS );
DrawItem( pDC, iRow, item_rect ); // draw item [see below]
*pResult = CDRF_SKIPDEFAULT;
}
else if( pLVCD->nmcd.dwDrawStage == CDDS_ITEMPOSTPAINT )
*pResult = CDRF_DODEFAULT;
}
void CMusikPlaylistCtrl::DrawItem( CDC* pDC, int item, const CRect& rect )
{
CMemDC dc( pDC, &rect );
// setup the font and highlight colors
COLORREF bg = GetSysColor( COLOR_BTNHILIGHT );
COLORREF text = GetSysColor( COLOR_WINDOWTEXT );
// color each sub item
CRect rcSubItem;
dc.SetTextColor( text );
for ( size_t i = 0; i < m_Prefs->GetPlaylistColCount(); i++ )
{
GetSubItemRect( item, i, LVIR_BOUNDS, rcSubItem );
dc.FillSolidRect( &rcSubItem, bg );
dc.TextOut( rcSubItem.left + 6, rcSubItem.top, _T( "Test" ) );
}
}
Any suggestions or advice as to how to speed this up would be much
appreciated. Thanks!
Casey
- 14
- MFC >> SocketHow can I connect to smtp server?
I tried to use CSocket:
CSocket csk;
csk.Create();
csk.Connect("server.com", 25);
but there is an error during connecting to server.com (function Connect
return false)....
Thx for help me
ArtuS
- 15
- MFC >> mfc class wizard pops up everytime!hi,
i just started with vc7 with an MFC dialog box project. I added
some controls and attached variables... it worked out fine. I
don't know what happened but now every control I doubleclick
pops up the MFC Class Wizard. Right-clicking any control does
not show the ADD VARIABLE option anymore. The ClassView
does not show TestMFCDlg as a class anymore (the AboutDlg
class is there and I can add variables to it as well!)
Can somebody please tell me what went wrong?
IDE version: 7.0.9466
Thank you.
dtor
|
| Author |
Message |
bob13251

|
Posted: Wed Nov 03 04:08:01 CST 2004 |
Top |
Visual Basic [VB] >> Strange Error - WebClient DownloadData
Hello,
I am trying to download web data into my current application. Failing
many attempts I tried to run the sample from the MS Help files with no
luck. If I create a new solution and put the sample code on a button
then it works. However, when do the same on a new form in my existing
solution then I get following error. Could there be some global
settings in my application that are causing problems?
Thanks in advance,
-Dave
Error:
-----------------------------------------------
An unhandled exception of type 'System.Net.WebException' occurred in
system.dll
Additional information: An exception occurred during a WebClient
request.
Sample Code:
-----------------------------------------------
Dim remoteUrl As String = "http://www.msn.com"
' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient
' Download the home page data.
Console.WriteLine(("Downloading " + remoteUrl))
' Downloads the Web resource and saves it into a data buffer.
' !!!!!!!!!! THIS LINE CAUSES THE ERROR !!!!!!!!!!!!!!!
Dim myDatabuffer As Byte() = myWebClient.DownloadData(remoteUrl)
' Display the downloaded data.
Dim download As String =
System.Text.Encoding.ASCII.GetString(myDatabuffer)
Console.WriteLine(download)
Console.WriteLine("Download successful.")
Visual Studio109
|
| |
|
| |
 |
Cor

|
Posted: Wed Nov 03 04:08:01 CST 2004 |
Top |
Visual Basic [VB] >> Strange Error - WebClient DownloadData
Dave,
I think that for most of us that is impossible to see without the code that
generates the error.
Cor
"Dave Starman" <EMail@HideDomain.com>
> Hello,
>
> I am trying to download web data into my current application. Failing
> many attempts I tried to run the sample from the MS Help files with no
> luck. If I create a new solution and put the sample code on a button
> then it works. However, when do the same on a new form in my existing
> solution then I get following error. Could there be some global
> settings in my application that are causing problems?
>
> Thanks in advance,
>
> -Dave
>
>
> Error:
> -----------------------------------------------
> An unhandled exception of type 'System.Net.WebException' occurred in
> system.dll
>
> Additional information: An exception occurred during a WebClient
> request.
>
>
> Sample Code:
> -----------------------------------------------
> Dim remoteUrl As String = "http://www.msn.com"
>
> ' Create a new WebClient instance.
> Dim myWebClient As New System.Net.WebClient
>
> ' Download the home page data.
> Console.WriteLine(("Downloading " + remoteUrl))
>
> ' Downloads the Web resource and saves it into a data buffer.
>
> ' !!!!!!!!!! THIS LINE CAUSES THE ERROR !!!!!!!!!!!!!!!
> Dim myDatabuffer As Byte() = myWebClient.DownloadData(remoteUrl)
>
> ' Display the downloaded data.
> Dim download As String =
> System.Text.Encoding.ASCII.GetString(myDatabuffer)
>
> Console.WriteLine(download)
> Console.WriteLine("Download successful.")
|
| |
|
| |
 |
| |
 |
Index ‹ Visual Studio ‹ Visual Basic [VB] |
- Next
- 1
- Visual Basic >> Accessing the Created Instance of a form in my modulesHello,
I need to create a single (new) instance of a FORM and have that instance
available to be called from my modules and some other forms. This is how I
launch it, from <FormAnyform>
Option Explicit
Dim WithEvents frmNew as myExistingForm
---------------------------
Private Sub InitializeNewStuff()
Set frmNew = New frmSomething
frmNew.Hide
End Function
I can't use frmSomething.Show, as I normally do and need to
create an instance (to work with a UserControl and Events)
but now I cannot access frmNew form my modules...
For example frmNew.Caption="Hello" cannot happen as
frmNew is not "public".
If I try frmSomething.Caption="Hello" then I launch a NEW, second
instance of frmSomething.... this is bad.
How can I set frmNew to a Global so I can just use frmNew after it
is created throughout my program?
Thanks
-stone
because of a UserControl and requirement of RaiseEvents)
- 2
- Visual Studio C++ >> What is returned?Why does one work and not the other?
Does Work:
::MessageBox(::GetActiveWindow(),CString((test = "Hello")) +
CString((test = "Hi")),"IDS_STRING102",MB_OK);
Does NOT work:
::MessageBox(::GetActiveWindow(),CString((test = "Hello",test)) +
CString((test = "Hi",test)),"IDS_STRING102",MB_OK);
Reason:
I wanted this macro to work:
#define GETRESOURCESTRING(iResID, out_CStringRef) CString((
VERIFY(out_CStringRef.LoadString(iResID)), (out_CStringRef) ))
...but as it stands, if you make the call:
CString test;
::MessageBox(::GetActiveWindow(),GETRESOURCESTRING(IDS_STRING102,test)
+ GETRESOURCESTRING(IDS_ABOUTBOX,test),"IDS_STRING102",MB_OK);
...its fails. It only works if you have two distinct strings:
CString test, test2;
::MessageBox(::GetActiveWindow(),GETRESOURCESTRING(IDS_STRING102,test)
+ GETRESOURCESTRING(IDS_ABOUTBOX,test2),"IDS_STRING102",MB_OK);
I guess I was under the impression that there would have been two
distinct CStrings on the stack that would have recieved their value
from "test" at two distinct times where test equaled two different
things...?
Apparently clueless,
BuddyLeeJr
- 3
- Visual Basic >> Copying Data from app to emailHow would you go about starting default email program and copying
specified text from a vb app to the email,text has to go in the subject
line and different text in body.Reason for this is I want to try and
simplify a program licensing.Click "reg button" and email starts and
has a subject line filled in and the programs serial is entered in the
body and an email address is entered.Any sample code or a pointer to
freeware/shareware that does this will be greatly appreciated.
thanks
SteveC
- 4
- Visual Studio C++ >> Winsock Sample?Dear all,
I would like to know are there any examples using winsock to send data
continuous thru server and client? Thank you for all of your help.
Alex Yung
- 5
- Visual Basic >> Tokenizer in UnicodeHello,
ich want divide an Unicode-Text (for instance rushian) in single words to
write them in a db. Each punctuation sign should be seperated from the
words. For non-unicode there are the api IsCharAlphaNumeric with the 1-byte
parameter of the letter. Unicode is 2 byte and therefore this function
doesn't work.
How is it possible to get all words in an rtf-ctl which has unicode text
(SelStart and SelLength and therefore SelText would be needed)
thanks Peter
- 6
- Visual Basic [VB] >> No "MS .NET Framework 1.1 Wizards"Hello,
I use "Microsoft .NET Framework 1.1 Wizards" on some machines
to change security settings tu use applications made with VB.Net 2003.
Some other machines don't have it.
I guess there is some kind of minimal client/framework to install.
Where can I get it (for Windows XP 2002 SP1) ?
Thanks !
- 7
- Visual Basic >> A question about optimizing/streamliningSo I was bored for a couple days after work and ended up writing a
program that essentially "simulates" a fireworks display. My problem is
that for some reason if I have any more than 70ish particles (an object
array of circle shapes) on screen at once the program starts to chug
pretty badly. I can post the code when I get home, but for now I can
explain the basic functioning so hopefully one of you can tell me why it
is running so ineffeciently.
Ok so on the form there are 3 timers. One timer cycles to determine the
time interval between launches, another timer cycles to regulate the
movement of the "launch" particle (the one the moves upward from the
ground), and the third one regulates the array of "explosion" particles.
Shapes and timers only load when necessary and at the end of their
lifecycle they are unloaded.
During the explosion particles life the first thing that happens is the
ExplosionParticleTImer(Index) loads and if the cycles for the timer = 0
it loads the associated particle( Particle(Index) ) and rolls a bunch of
randoms to determine trajectory (angle) and speed from the point of
explosion. Every time the timer cycles after that it uses a fractional
exponential equation to determine the "speed" (in other words how many
units of X and Y movement).
Also, each cycle the particles subtract value from the RGB values which
makes the particles fade to black.
So that is pretty much the synopsis of the program. I'm not very savvy
regarding the underlying aspects of memory use in programming so I don't
really even know where to start fixing the program. If you guys have any
input I'd apperciate it, and as soon as I get back I'll figure out how
to post the code.
*** Sent via Developersdex http://www.developersdex.com ***
- 8
- Visual Studio C++ >> C preprocessor directive #ifGreetings,
I am using C and in several places I want to select the code to be
compiled base on the size of a typedef. Though the snippet below does
not work it may illustrate my desire.
Thanks,
gtb
#if sizeof(MY_TYPE) = sizeof(int)
#define INT
#endif
...
...
#ifdef INT
//Use int based printf.
#else
//Use struct based printf
#endif
- 9
- Visual Basic >> convert byte to stringHello
I have the following :
dim s as string
dim b as byte
b has a value of 97 (ordinal value of character "a" )
How can "s" get the value from b ?
Thanks :)
- 10
- MFC >> No refresh CTreeCtrlHow to update a CTreeCtrl, without repaint it?
So, I refresh only one time and my program becomes more fast.
Thanks
Carlos
- 11
- MFC >> SetMenuItemBitmapsHi,
I use suggested SetMenuItemBitmaps for putting bitmaps intop menu,
but is there possible to have background under these bitmaps,
like in XP style dropdown menu?
I know there some articles how to do owner drawn menu, but jus wander
if for putting such vertical background is that necessary,
thanks
- 12
- Visual Studio C++ >> using swap to make assignment operator exception safeHello everyone,
The following swap technique is used to make assignment operator exception
safe (means even if there is exception, the current object instance's state
is invariant).
It used a temporary object "temp" in this sample, and assignment is made on
a to temp ar first. Even if there is exception, the current this object's
state is not corrupted.
My question is, the pattern works only if there is no exception thrown by
swap function. If there are exception in swap function, the state of current
object instance may still be corrupted (swap may invoke the assignment
operator of member variables). Is my understanding correct?
[Code]
class A;
A& A::operator= (const A& a)
{
A temp;
temp = a; // exception may be thrown
swap (*this, temp);
return *this;
}
[/Code]
thanks in advance,
George
- 13
- Visual Basic >> Upgrade?No sooner had I spent a lot of money on VB6
Professional and books to learn how to use it than M$
came out with VB.NET. At that point I gave up for a
while. Now I have a few questions.
1) Does VB.NET make VB6 obsolete?
2) Is there a way to upgrade from VB6 to VB.NET without
spending several hundred more dollars, and is it
necessary?
3) Should I just give up and resign myself to using this
machine as nothing more than a really expensive video
game?
I'll look here once in a while for answers, but I
suspect I already know the answers to those questions -
Yes, No, Yes.
- 14
- Visual Basic >> Err.DescriptionLooking through some old code I see the statement MsgBox Error$
If this any different to MsgBox Err.Description
Thanks,
Chris
- 15
- VB Scripts >> vbscript for ADAMI am a sys admin for a small/medium size company and would like to
investigate utilizing vbscript to automate tasks on an ADAM install.
Ex. How to create an OU object via vbscript, user object etc...
|
|
|