|
|
I am trying to use a FolderBrowserDialog to get a folder and set the path to a text field on my form. The first problem I came up against was a blank folder listing which I had to rectify by making the FolderBrowserDialog spawn as a STA ApartmentState. Now the problem is that I can't get the SelectedPath back onto my calling form.
Here is my code for my Click event to open the FolderBrowserDialog and the subsequent settings:
private: System::Void OnClicked_ID_GETPHOTO_DIR(System::Object^ sender, System::EventArgs^ e) {<br />
Thread^ newThread = gcnew Thread ( gcnew ThreadStart( this, &Picture_Importer::Form_Start::Get_Directory ) );<br />
newThread->SetApartmentState(ApartmentState::STA);<br />
newThread->Start();<br />
}<br />
<br />
private: void Get_Directory() {<br />
this->folderBrowserDialog1->SelectedPath = "c:\\";<br />
<br />
this->folderBrowserDialog1->Description = "Select the directory that you want to use as the default.";<br />
<br />
this->folderBrowserDialog1->ShowNewFolderButton = false;<br />
<br />
System::Windows::Forms::DialogResult result = folderBrowserDialog1->ShowDialog();<br />
if ( result == ::DialogResult::OK )<br />
{<br />
folderName = folderBrowserDialog1->SelectedPath;<br />
this->ID_PHOTO_DIR->Text = folderName;<br />
}<br />
<br />
}
The problem is when I run the code and it gets to this->ID_PHOTO_DIR->Text = folderName; it chokes with
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll<br />
<br />
Additional information: Cross-thread operation not valid: Control 'ID_PHOTO_DIR' access from a thread other than the thread it was created on.
I am new to this programming language, so please be gentle with me. I appreciate what the message is saying I just don't get how to fix it.
|
|
|
|
|
|
Hi!!
I've been reading about multithreading in this page, but i can't compile the example written here.
I'm using Borland C++ 5.5.1 for Win32 and my config files are
bcc32
-I"C:\Borland\BCC55\Include"<br />
-L"C:\Borland\BCC55\Lib;C:\Borland\BCC55\Lib\PSDK<br />
-P<br />
-v-<br />
-w<br />
-D_WIN32_WINNT=0x0400
Ilink32
-v-<br />
-x<br />
-L"C:\Borland\BCC55\Lib;C:\Borland\BCC55\Lib\PSDK;C:\WINDOWS\system32"
And the error that the compiler gives me is
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland<br />
thread.c:<br />
Error E2268 thread.c 30: Call to undefined function '_beginthread' in function main()<br />
Error E2268 thread.c 46: Call to undefined function '_endthread' in function ThreadProc(void *)<br />
*** 2 errors in Compile ***<br />
can someone help me??
what am i doing wrong??
i'am a beginner in multithreading...
greetings!!
|
|
|
|
|
venetus wrote: I'm using Borland C++ 5.5.1
Then you can't possibly be using C++/CLI. You could try the visual C++ forum, but a Borland forum would be more sensible, if there is one.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
As I can see there is no problem with multithreading, but with the functions You've used. Compiler doesn't know these functions. Have you included <process.h> ??
|
|
|
|
|
i just copy and pasted the example...
what do you think i have to include???
|
|
|
|
|
i've just compile the example with Dev and it worked. But i don't know why it doesn't work with Borland compiler...
Any hint?
|
|
|
|
|
Which example? There are 3 examples
|
|
|
|
|
this one "Download demo project in C - 3 Kb"
bye
|
|
|
|
|
I've tried it with Builder 6.0 and it's worked fine.
Probably you haven't checked the Multi Threaded check box in File\new\other...\console wizard dialog. Make sure it's checked.
|
|
|
|
|
this is STILL the wrong forum to be talking about this.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i would add a dll in my project but i don't know how i can introduce him, iam viewing a reference but i can't add him, i work with Visual Studio 2005 please help me.
Thank you very mutch.
|
|
|
|
|
What is the DLL written in ? You can add references to COM dlls and .NET dlls ( assuming your question is in the right forum and you are using C++/CLI ), I don't think you can import plain dlls, you can p/invoke them ( again, if you really are using C++/CLI ).
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hey guys,
few days ago somebody ask me that where it is mandatory to define copy constructor i.e without making an explicit call we can not solve our problem..
so i need to know what would be that condition as i am also searching for the same from 2-3 days ...
if anybody can help me in getting the answer i'll greateful to him/her..
Thank you
Regards,
Pankaj Sachdeva
|
|
|
|
|
pan_angel wrote: where it is mandatory to define copy construc
It is not mandateroy to define copy c'to. But, it is required to define in cases where, one of member variable is pointer and uses dynamic memory allocation.
class A
{
char *m_pName;
int m_nid;
public:
A(char *pName,int nId)
{
m_pName = new char [strlen(pName)+1] ;
strcpy(m_pName,pName);
nid = nId;
}
~A()
{
delete []m_pName;
m_pName = NULL;
}
};
int main()
{
A aObj("Prasad",1);
A aObj1 = aObj;
}
So should modify your defintion to,
class A
{
char *m_pName;
int m_nid;
public:
A(char *pName,int nId)
{
m_pName = new char [strlen(pName)+1] ;
strcpy(m_pName,pName);
m_nid = nId;
}
A(A& aObj)
{
int nMemoryToAlloacate = strlen(aObj's char pointer);
m_pName = new char [nMemoryToAlloacate + 1] ;
strcpy(m_pName,aObj's char pointer);
m_nid = aObj's m_nid ;
}
~A()
{
delete []m_pName;
m_pName = NULL;
}
};
|
|
|
|
|
Objects can be passed to functions by value or by reference. If they are passed by value, a copy of each object is passed to the function. The default method for creating the copy is memberwise copy (shallow copy). This can be modified by supplying a user-defined copy constructor.
|
|
|
|
|
This is not a C++/CLI question, it should have been asked in the Visual C++ forum. You need a copy constructor when you have a pointer, or whenever you have an object which would automatically only provide a shallow copy, and a deep copy is required.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hello,
I'm trying to create a Observer functionallity between a unmanaged C++ and a managed C++ Class. My managed C++-Class will be used as a Wrapper Class to connect the unmanaged Code to a C# Class. Now I have a Interface Class in my unmaganed Code and wanted to heritate my Wrapper-Class from it. But there ist the Problem. Its not possible to heritate a managed class from a unmanaged class.
The aim is, that my unmanaged Code has to call a method in managed Code.
Can someone help me to find an other solution?
Thanks
|
|
|
|
|
I did a similar thing with containment. The manaed object contains the unmanaged object and exposes all the same methods but with dot net data types. Each method converts data types of params if nessasary and cals the method on the unmanaged object. See this wonderfull article[^] for a smart pointer template you can use to manage the lifetime of unamanged objects
System.IO.Path.IsPathRooted() does not behave as I would expect
|
|
|
|
|
Thanks for your advice. The smart pointer template works great.
|
|
|
|
|
I am trying to build MagickNet (http://midimick.com/magicknet/) and I am not very familiar with c++ but I got pretty far. I am using VS2005 Express and the Platform SDK 2003 R2 is loaded an configured. I downloaded the source for this project and the source for the ImageMagic and GhostScript code to satisify any requirements that MagickNet needed.
I started this project by clicking on File -> New -> Project from existing code. I hacked away until I could right click on each cpp file and compile it with out errors. I have my configuration for a release build. I don't care for the debug because I only need the release version.
However when I try to build the project I get the following error:
------ Build started: Project: MagickNet, Configuration: Release Win32 ------
Compiling...
Stdafx.cpp
MagickOptions.cpp
MagickNet.cpp
MagickImages.cpp
MagickImage.cpp
MagickGeometry.cpp
MagickColor.cpp
AssemblyInfo.cpp
Linking...
LINK : fatal error LNK1104: cannot open file '.\Release\AssemblyInfo.obj'
Build log was saved at "file://c:\Documents and Settings\cjohnson\My Documents\Visual Studio 2005\Projects\MagickNet\Release\BuildLog.htm"
MagickNet - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I don't know much about VC++ but it seems like it is not creating the object files. If you need more info I can post off of my command parameters from VS2005 c++ express edition.
Can anyone help me please?
Thanks
|
|
|
|
|
I suspect that ImageMagic is not a .NET program, and you are therefore in the wrong forum. You are using Visual C++, right ? There's a Visual C++ forum. This one is for C++/CLI.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks Christian. I've just posted this in the c++ forum. I am using vc++ but I am building it for a c#/asp.net website. I guess I should have put the horse before the cart.
Thanks,
Craig
|
|
|
|
|