|
|
Hi,
I converted a sample code from C# to VC++. But I don't know how to change the "WaitCallback" statements to avoid getting error while compiling!? Here is my translated code:
Translated code to VC++
#include "stdafx.h"<br />
<br />
using namespace System;<br />
using namespace System::Threading;<br />
<br />
public ref class SomeState{<br />
public: <br />
int Cookie;<br />
public:<br />
SomeState(int iCookie)<br />
{<br />
Cookie = iCookie;<br />
}<br />
};<br />
<br />
public ref class Alpha{<br />
public:<br />
array<int>^ HashCount; <br />
ManualResetEvent^ eventX;<br />
static int iCount;<br />
<br />
static int iMaxCount;<br />
Alpha(int MaxCount) <br />
{<br />
iCount = 0;<br />
HashCount = gcnew array<int>(30);<br />
iMaxCount = MaxCount;<br />
}<br />
<br />
public:<br />
void Beta(Object^ state)<br />
{<br />
Console::WriteLine(" {0} {1} :", Thread::CurrentThread->GetHashCode(), (dynamic_cast<SomeState^>(state))->Cookie);<br />
Interlocked::Increment(HashCount[Thread::CurrentThread->GetHashCode()]);<br />
<br />
int iX = 10000;<br />
while (iX > 0){ iX--;}<br />
if (Interlocked::Increment(iCount) == iMaxCount) {<br />
Console::WriteLine("Setting EventX ");<br />
eventX->Set();<br />
}<br />
}<br />
};<br />
<br />
public class SimplePool<br />
{<br />
public:<br />
static int Main(array<System::String ^> ^args)<br />
<br />
{<br />
Console::WriteLine("Thread Simple Thread Pool Sample");<br />
int MaxCount = 1000;<br />
ManualResetEvent^ eventX = gcnew ManualResetEvent(false);<br />
Console::WriteLine("Queuing {0} items to Thread Pool", MaxCount);<br />
Alpha^ oAlpha = gcnew Alpha(MaxCount);<br />
oAlpha->eventX = eventX;<br />
Console::WriteLine("Queue to Thread Pool 0");<br />
SomeState^ sstate0=gcnew SomeState(0);<br />
ThreadPool::QueueUserWorkItem(gcnew WaitCallback(oAlpha->Beta),sstate0);<br />
for (int iItem=1;iItem < MaxCount;iItem++)<br />
{<br />
Console::WriteLine("Queue to Thread Pool {0}", iItem);<br />
SomeState^ sstatei=gcnew SomeState(iItem);<br />
ThreadPool::QueueUserWorkItem(gcnew WaitCallback(oAlpha->Beta), sstatei);<br />
}<br />
Console::WriteLine("Waiting for Thread Pool to drain");<br />
eventX->WaitOne(Timeout.Infinite,true);<br />
Console::WriteLine("Thread Pool has been drained (Event fired)");<br />
Console::WriteLine("Load across threads");<br />
for(int iIndex=0;iIndex<oAlpha->HashCount->Length;iIndex++)<br />
Console::WriteLine("{0} {1}", iIndex, oAlpha->HashCount[iIndex]);<br />
return 0;<br />
}<br />
};
(You can find the original code in the
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEV.v10.en/dndotnet/html/dotnetperftechs.htm)
Original code in C#
using System;<br />
using System.Threading;<br />
<br />
public class SomeState{<br />
public int Cookie;<br />
public SomeState(int iCookie){<br />
Cookie = iCookie;<br />
}<br />
};<br />
<br />
<br />
public class Alpha{<br />
public int [] HashCount;<br />
public ManualResetEvent eventX;<br />
public static int iCount = 0;<br />
public static int iMaxCount = 0;<br />
public Alpha(int MaxCount) {<br />
HashCount = new int[30];<br />
iMaxCount = MaxCount;<br />
}<br />
<br />
<br />
public void Beta(Object state){<br />
Console.WriteLine(" {0} {1} :", <br />
Thread.CurrentThread.GetHashCode(), ((SomeState)state).Cookie);<br />
Interlocked.Increment(ref HashCount[Thread.CurrentThread.GetHashCode()]);<br />
<br />
int iX = 10000;<br />
while (iX > 0){ iX--;}<br />
if (Interlocked.Increment(ref iCount) == iMaxCount) {<br />
Console.WriteLine("Setting EventX ");<br />
eventX.Set();<br />
}<br />
}<br />
};<br />
<br />
public class SimplePool{<br />
public static int Main(String[] args) {<br />
Console.WriteLine("Thread Simple Thread Pool Sample");<br />
int MaxCount = 1000;<br />
ManualResetEvent eventX = new ManualResetEvent(false);<br />
Console.WriteLine("Queuing {0} items to Thread Pool", MaxCount);<br />
Alpha oAlpha = new Alpha(MaxCount);<br />
oAlpha.eventX = eventX;<br />
Console.WriteLine("Queue to Thread Pool 0");<br />
ThreadPool.QueueUserWorkItem(new WaitCallback(oAlpha.Beta),new SomeState(0));<br />
for (int iItem=1;iItem < MaxCount;iItem++){<br />
Console.WriteLine("Queue to Thread Pool {0}", iItem);<br />
ThreadPool.QueueUserWorkItem(new WaitCallback(oAlpha.Beta),<br />
new SomeState(iItem));<br />
}<br />
Console.WriteLine("Waiting for Thread Pool to drain");<br />
eventX.WaitOne(Timeout.Infinite,true);<br />
Console.WriteLine("Thread Pool has been drained (Event fired)");<br />
Console.WriteLine("Load across threads");<br />
for(int iIndex=0;iIndex<OALPHA.HASHCOUNT.LENGTH;IINDEX++)<br />
Console.WriteLine("{0} {1}", iIndex, oAlpha.HashCount[iIndex]);<br />
}<br />
return 0;<br />
}<br />
}
I get these errors:
Error C3867: 'Alpha::Beta': function call missing argument list; use '&Alpha::Beta' to create a pointer to member
Error C3350: 'System::Threading::WaitCallback' : a delegate constructor expects 2 argument(s)
AlwaysStudent
|
|
|
|
|
Hi,
most problems can be solved easily by using the line numbers, either the ones mentioned
in compile errors or in Exception.ToString() output.
Advice: tell Visual Studio to always show line numbers in source files (Tools/Options/
Text Editor/All Languages...).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
AlwaysStudent wrote: gcnew WaitCallback(oAlpha->Beta)
Replace the above code with: gcnew WaitCallback(oAlpha, &Alpha::Beta)
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
George L. Jackson,
Thanks a lot, that is working now.
Berst Regards,
AlwaysStudent
AlwaysStudent
|
|
|
|
|
Hi,
I want to connect two combo boxes, it means that when i choose a data from the list of first combo box, the list box or edit box of second combo box change according to first combo box.
my program is on C++ language(MFC).
(i use embedded software)
please help me.
thanks a lot
|
|
|
|
|
Miss_F wrote: my program is on C++ language(MFC)
You should post this on the proper message board...
The Visual C++/MFC Board[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Next time,please post at the correct forum.
You can use of m_combo2.SetCurSel(m_Combo1.GetCurSel()); .
|
|
|
|
|
Hi,
Thanks a lot and sorry for this mistake.
|
|
|
|
|
|
Hi, I am using Visual Studio 2005 C++/CLI. I have also posted this on the Visual Studio IDE message board. I have been developing an application on my PC at my desk. This application uses the Microsoft.Office.Interop.Excel assembly that I included by adding a new reference in the project properties page by clicking the 'Add New Reference' button and selecting it from a list. I then copied the project to another machine that has Visual Studio 2005 installed on it and the compiler choked on the Excel reference. I went to add the reference to the project properties page but could not find it in the pre-defined list. I went back to my original machine and could not find Microsoft.Office.Interop.Excel in the pre-defined list either. Shouldn't this assembly be in the pre-defined list or is it defined differently? How do I get this assembly in the Visual Studio 2005 reference list? I did it once and I'm almost positive it was in the pre-defined list. What happened to it?
Thanks
Buck
|
|
|
|
|
From http://msdn2.microsoft.com/en-us/library/kh3965hw(VS.80).aspx :
During a Typical installation of Microsoft Office, the primary interop assemblies are set to be installed on first use IF the .NET Framework IS INSTALLED. This installation option works on development computers during project creation and on end user computers when an end user runs a Microsoft Office solution.
Redistributable Primary Interop Assemblies Package
The primary interop assemblies for Microsoft Office products are also available in a redistributable Microsoft Windows Installer package:
The package for Microsoft Office 2003 is available for download from the Microsoft Download Center (http://go.microsoft.com/fwlink/?LinkId=50479).
The package for the 2007 Microsoft Office system is available for download from the Microsoft Download Center (http://go.microsoft.com/fwlink/?LinkId=72637).
|
|
|
|
|
I converted a VS 6 project to VS 2005. When I execute my 2005 project none of my ON_EVENTS_ work. Any fix?
|
|
|
|
|
aschwarz wrote: I converted
what does "converted" mean? Does it mean Visual Studio prompted you to do the conversion and you clicked Yes or OK?
|
|
|
|
|
Yes. I accessed a <name>.dsp file in VS 2005 and was prompted to convert the project. Let me retract my statement. My ON_EVENT_s do indeed seem to be tracking but the results are not as expected. I'm sorry, I misspoke and have to do some additional research.
There is one other annoyance. Whenever I do a build I get a message that the 'hcw' can't be found. Help seems to think that this is a utility. Any idea how to get rid of it?
Thank you for your response. I am sorry that I goofed.
|
|
|
|
|
aschwarz wrote: I am sorry that I goofed.
No problem. Let's get this out of the way first, if you are not converting your project to a "managed" (.NET) project then this is the wrong forum for your posts. The Visual C++ / MFC forum is for "native" project questions.
aschwarz wrote: I get a message that the 'hcw' can't be found. Help seems to think that this is a utility. Any idea how to get rid of it?
Yes it was the old Help Workshop compiler. Along the way they switched to HTML help and there is a new system for that. I have no idea how to convert the "help" part of the project. The utilities probably run as custom compiler steps so you can likely eliminate the compiler error by removing the custom step but then the help will not build. I can point you to this starter MSDN documentation for HTML Help[^] but I have no idea how to convert the project from HCW to HTML help
|
|
|
|
|
Can anyone here help me please and tell me how can i establish a DATA connection in C++, that work with OLE DB?
I would like from my C++ Programme(Visual Studio 2005)to connect the MS SQL Server 2005 through OLE DB, but i do not have any idea how to do this, this field is new for me.
I installed already MDAC 2.8, which it contains the OLE DB, and furthermore i can not do any thing, i do not even what is the next step is. Do i have MDAS 2.8 or not ?
I searched the whole day in the Internet, but without any success. What could help me is a small applicable example in C++, that describes how can i make a connection how can i inquire(call) the DB.
Another thing, should i set something in the Comp. or install something else?
Can anyone help me please or tell me where i can find the acquired information?
Regards in Advance
FreeEagle
|
|
|
|
|
FreeEagle wrote: I searched the whole day in the Internet, but without any success.
Your post suggests your reading skills are not strong enough to be a software developer. You posted this in the wrong forum, also because you apparently can't read. You should consider a career change.
This site has 10s of articles that give examples of everything you likely need to know about working with databases from C++, not to mention the miles of them on the MSDN web site. If you can't find any of them it seems doubtful you have the capacity to develop working software.
|
|
|
|
|
@ Led mike:
Is that your way to help people? It is arrogant and unashamed to treat people this way.
What a pity, that I got such an answer,which did not help me, but just want to bring me down.
Notices or any Tips to any Web Pages, which could show me how can I solve the problem, would be helpful more than your stupid comment. I wrote from the beginning that I am a beginner, and did not claim that I am a great Software developer. I just started to learn this, and I will never ever let anyone (especially a person like you) to bring me down.
Thanks God that there are many people in other Forums,which are not like you, and could help me in this matter.
FreeEagle
|
|
|
|
|
I started to reply to your post but then I remembered you can't read
|
|
|
|
|
I create a windows form apllication, p2pport.
My form file name is Dlg.I get some errors.
error C2027: use of undefined type 'p2pport::CParams'
error C2227: left of '->setValue' must point to class/struct/union/generic type
in Dlg.cpp
params->setValue("Y", "123");
in my Dlg.h file
#include "params.h";
namespace p2pport {
using namespace System;
...............................
public ref class Dlg : public System::Windows::Forms::Form
{
CParams* params;
}
}
in my param.h file
class CParams{
void setvalue(char* k, char* v);
}
in my params.cpp
void CParams::setValue(char* k, char* v){ ..... return; }
Can anybody tell me what's wrong with it?
Appreciate your reply.
Jane
|
|
|
|
|
minihotto wrote: Can anybody tell me what's wrong with it?
Jane one of your compiler errors....
minihotto wrote: error C2027: use of undefined type 'p2pport::CParams'
"use of undefined type" is a beginner level error. Using forums to learn novice programming skills is sub-optimal. I strongly urge you to find some novice level books for programming and learn from them. When you need help understanding something from a book you can post the statement you don't understand in a forum and ask for clarification.
|
|
|
|
|
Jane, please note:
1. C++ and C++/CLI are case-sensitive.
2. C++ and C++/CLI classes are private by default.
3. Your CParams class is not int the p2pport namespace
4. Please use more descriptive subject line.
5. Don't disregard Mike's comments.
-- modified at 19:49 Wednesday 7th November, 2007
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
How can one implement a COM event sink with 'Windows Forms Application' with .NET 2005? Found plenty of examples on how to do it using MFC, but no luck witn CLI yet.
Anyone solved this tricky operation yet? I managed to implement one solution with 2003-version (it's not using CLR:pure or :safe, but CLR:oldformat), yet a problem exists on how to tell the Forms application the parameters (i.e. how to display the received parameters in controls).
|
|
|
|
|
eero_p wrote: with 2003-version (it's not using CLR:pure or :safe, but CLR:oldformat), yet a problem exists on how to tell the Forms application the parameters (i.e. how to display the received parameters in controls).
I don't understand. Perhaps you could post the relevant code that is problematic along with the compiler errors.
|
|
|
|