|
Hi. I'm using Visual Studio 2005 C++/CLI. I have a file that has its contents read into an array, one line of the file per element of the array. There may be 10 elements to read or 10,000 elements to read. I would like to define the array size dynamically by reading each line of the file, counting until all the lines are read. Then I want to go back to the begining of the stream but there is no Seek() function. I tried streamReader->Close() and then another streamReader = gcnew StramReader(fileStream) but that doesn't work. Can I reset the streamReader back to the beginning?
Thanks
Buck
|
|
|
|
|
I think you can access the Seek method through the StreamReader's BaseStream property. I'm not by a C++ compiler so I can't test this.
Try this out:
FileStream* fs = new FileStream(S"YourFile.txt", FileMode::???, FileAccess::???);
StreamReader* sr = new StreamReader(fs);
sr->BaseStream->Seek(0, SeekOrigin::Begin);
I think you will also need to call sr->DiscardBufferedData() after the Seek or you will get unexpected results.
|
|
|
|
|
Thanks Robert,
Yes, that works.
The key here is the sr->DiscardBufferedData() otherwise the sr->BaseStream->Seek() function does nothing.
Buck
|
|
|
|
|
Hello guys,
I'm trying to execute a *.exe file from an own win api. Of course I looked through the internet but all i could find was ShellExecute() and CreateProcess() which, for any reason, don't work in VC++2008. Do I need to include any special library files or headers to get access to these functions, or is there another way to start a program from my win api?
Thanks ans best wishes,
Manfred
|
|
|
|
|
Hi,
if you want to create a process, maybe you should read up on the Process class?
|
|
|
|
|
Austrian_Programmer wrote: Do I need to include any special library files or headers to get access to these functions
ShellExecute()
Header - shellapi.h
Import library - shell32.lib
CreateProcess()
Header - Declared in Winbase.h; include Windows.h.
Library - Use Kernel32.lib.
|
|
|
|
|
Thanks, but you need windows.h in both cases.
I tried the ShellExecute() function with the included header and library, but nothing happens, the specified program didn't start.
<br />
#pragma once<br />
#pragma comment(lib, "shell32.lib")<br />
<br />
#include <windows.h><br />
#include <shellapi.h><br />
<br />
<br />
char *pcOp = "open";<br />
char *pcPath = "calc.exe";<br />
ShellExecute(NULL, (LPCWSTR)pcOp, (LPCWSTR)pcPath, NULL, NULL, SW_SHOWNORMAL); <br />
</shellapi.h></windows.h>
As I run this code I didn't get any error messages but nothing happened.
What am I doing wrong?
|
|
|
|
|
Austrian_Programmer wrote: As I run this code I didn't get any error messages but nothing happened.
What am I doing wrong?
What was the return value from ShellExecute?
led mike
|
|
|
|
|
Austrian_Programmer wrote: ShellExecute(NULL, (LPCWSTR)pcOp, (LPCWSTR)pcPath, NULL, NULL, SW_SHOWNORMAL);
As I run this code I didn't get any error messages but nothing happened.
What am I doing wrong?
Casting char*s to wchar_t*s is not good.
You shouldn't use casts unless absolutely necessary. If it doesn't compile without
the casts, then I recommend looking at the types involved before covering the problem
with a cast.
Mark
|
|
|
|
|
Can we use the directshow methods in VC++ windows forms application. I have worked in VC++ MFC using Dshow methods and dont know how to use in VC++ Windows forms application. I got linker error when I use the Dshow methods, also I specified all the libraries in Project properties. Please advice.
Many thanks in advance.
|
|
|
|
|
What are the errors exactly?
Mark
|
|
|
|
|
1>------ Build started: Project: AV2USB, Configuration: Debug Win32 ------
1>Linking...
1>AV2USB.obj : error LNK2020: unresolved token (0A00000E) IID_IAMStreamConfig
1>AV2USB.obj : error LNK2020: unresolved token (0A00000F) IID_IBaseFilter
1>AV2USB.obj : error LNK2028: unresolved token (0A000011) "extern "C" void __stdcall VariantInit(struct tagVARIANT *)" (?VariantInit@@$$J14YGXPAUtagVARIANT@@@Z) referenced in function "private: void __clrcall AV2USB::Form1::button4_Click(class System::Object ^,class System::EventArgs ^)" (?button4_Click@Form1@AV2USB@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>AV2USB.obj : error LNK2020: unresolved token (0A000012) IID_IPropertyBag
1>AV2USB.obj : error LNK2020: unresolved token (0A000013) IID_ICreateDevEnum
1>AV2USB.obj : error LNK2020: unresolved token (0A000014) IID_ICaptureGraphBuilder2
1>AV2USB.obj : error LNK2020: unresolved token (0A000015) IID_IGraphBuilder
1>AV2USB.obj : error LNK2001: unresolved external symbol IID_IAMStreamConfig
1>AV2USB.obj : error LNK2001: unresolved external symbol IID_IBaseFilter
1>AV2USB.obj : error LNK2019: unresolved external symbol "extern "C" void __stdcall VariantInit(struct tagVARIANT *)" (?VariantInit@@$$J14YGXPAUtagVARIANT@@@Z) referenced in function "private: void __clrcall AV2USB::Form1::button4_Click(class System::Object ^,class System::EventArgs ^)" (?button4_Click@Form1@AV2USB@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>AV2USB.obj : error LNK2001: unresolved external symbol IID_IPropertyBag
1>AV2USB.obj : error LNK2001: unresolved external symbol IID_ICreateDevEnum
1>AV2USB.obj : error LNK2001: unresolved external symbol IID_ICaptureGraphBuilder2
1>AV2USB.obj : error LNK2001: unresolved external symbol IID_IGraphBuilder
1>E:\GUI\AV2USB\Debug\AV2USB.exe : fatal error LNK1120: 14 unresolved externals
1>Build log was saved at "file://e:\GUI\AV2USB\AV2USB\Debug\BuildLog.htm"
1>AV2USB - 15 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
|
|
|
You've included Strmiids.lib and Dxguid.lib in your build?
|
|
|
|
|
I have added Strmiids.lib already and tried including Dxguid.lib but still I got the same linker errors. Please help me if I miss something. The other libraries included are strmiids.lib strmbase.lib winmm.lib SetupApi.lib strmbasd.lib Dxguid.lib Quartz.lib ole32.lib. In addition to this there are default inherited libraries. They are as follows
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
odbc32.lib
odbccp32.lib
More interestingly, when I remove the libraries from the Project Properties->Linker->Input, I got the same errors. Please advice.
modified on Friday, June 27, 2008 6:13 AM
|
|
|
|
|
hmm the only thing I can think of is you've got the wrong SDK.
What version of Visual Studio?
What SDK version are you using?
Mark
|
|
|
|
|
Mark Salsbery wrote: What version of Visual Studio?
Visual Studio 2005
Mark Salsbery wrote: What SDK version are you using?
Microsoft Platform SDK for Windows Server 2003 R2
For your information, everything works fine with VC++ MFC and the problem now facing is with VC++ Windows application forms.
|
|
|
|
|
bhanu_8509 wrote: Windows application forms
As in .NET Forms (C++/CLR)?
In your VS settings (Tools/Options/Projects and Solutions/VC++ Directories)
are the header and lib folders for the PSDK searched BEFORE the default VS SDK
folders?
Do you use a stdafx.h file? If so, what's in there exactly?
|
|
|
|
|
Mark Salsbery wrote: As in .NET Forms (C++/CLR)?
I cant understand it. Please kindly explain me.
Mark Salsbery wrote: Do you use a stdafx.h file? If so, what's in there exactly?
#include <initguid.h>
#include <Strmif.h>
#include <Dshow.h>
Mark Salsbery wrote: In your VS settings (Tools/Options/Projects and Solutions/VC++ Directories)
are the header and lib folders for the PSDK searched BEFORE the default VS SDK
folders?
In the directory settings PSDK directories and libraries are included at the last ( I mean after the default VS SDK ).
Thanks for your prompt reply. I need some assistance very much to solve this issue.
|
|
|
|
|
That's all that's in your stdafx.h file?
bhanu_8509 wrote: In the directory settings PSDK directories and libraries are included at the last ( I mean after the default VS SDK ).
They need to be at the top! You want the headers and libraries from the PSDK Server 2003R2,
not the ones included with VS2005.
Note that in VS2008, the SDK is up to date with the addition of DirectShow, so the secondary
PSDK isn't necessary.
|
|
|
|
|
Mark Salsbery wrote: They need to be at the top! You want the headers and libraries from the PSDK Server 2003R2,
not the ones included with VS2005.
I got 88 errors after specifying PSDK above all. One of the error is
1>C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\strsafe.h(431) : error C3641: 'StringCchCopyA' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
Please advice.
|
|
|
|
|
bhanu_8509 wrote: Please advice.
The PSDK is native code right? You can't compile native code in a Pure managed project. The project has to be set up for mixed mode to use native code.
led mike
|
|
|
|
|
Can you please explain how to do this.
|
|
|
|
|
Can you please tell me how to do this. Please...
|
|
|
|
|
bhanu_8509 wrote: Please advice
See led mike's reply.
|
|
|
|
|
By the way, I just realized you're asking in the Managed C++/CLR forum,
so my Windows Forms question was silly
Mark
|
|
|
|