|
Again, with code cleaned up. My apologies.
<br />
Calling program:<br />
{<br />
GenericIo genericIo =<br />
new GenericIo<<br />
SomeTableAdaptors.SomeTableAdaptor,<br />
SomeDataSet.SomeDataTable>;<br />
<br />
SomeTableAdaptors.SomeTableAdaptor tableAdaptor =<br />
new SomeTableAdaptors.SomeTableAdaptor();<br />
SomeDataSet.SomeDataTable dataTable =<br />
new SomeDataSet.SomeDataTable();<br />
<br />
genericIo.GetDataTable(tableAdaptor, dataTable);<br />
}<br />
<br />
Generic class:<br />
public class GenericIo<T1, T2><br />
where T1 : class, new()<br />
where T2 : DataTable, new()<br />
{<br />
public void GetDataTable(T1 tableAdaptor, T2 dataTable)<br />
{<br />
tableAdaptor.Fill(dataTable);<br />
}<br />
}<br />
<br />
Compiler error message:<br />
'T1' does not contain a definition for 'Fill'<br />
|
|
|
|
|
This short bit of code works well for getting the VolumeSerialNumber using win32_logicaldisk:
ManagementObject disk=new
ManagementObject("win32_logicaldisk.deviceid='C:\'");
this.textBox2.Text = disk.Properties["VolumeSerialNumber"].Value.ToString();
However, I would like to get the manufacturer serial number. I know this is available in win32_PhysicalMedia, but I can't find anything that tells me precisely what the "serial number" is named.
|
|
|
|
|
A little Google goes a long way. All I did was search for "Win32_PhysicalMedia" and wallah[^]!!
It's called, oddly enough, SerialNumber . The problem you're going to run into is that there is nothing that says a manufacturer has to fill this field in. This field may come back empty for any given drive or media.
|
|
|
|
|
Yup. Did the Google thing. I always do before I bother all you hard working folks. Found the same thing you did, tried it, and my little app crashed -- thought maybe I hadn't found the right name after all.
I suppose, based on what you say, it might mean there is no serial for my harddrive.
Bummer.
|
|
|
|
|
The last time I did this, only 2 out of 6 of my drives filled in the Serial Number field...
|
|
|
|
|
That's too bad. It would sure make my life easier if it was a standard all manufacturers followed.
Thanks for the feedback.
|
|
|
|
|
i have written a c++ application now i want to override virtual event handlers in the c++ app with c#.
also i want to compile the c++ app - or part of it- as a dll that i can reference in c#. but i keep on getting an error saying it's not a com object...
problem
1. what type of project do i need to create for c++ to be accesible in c#
2. how do i override an event handler.
or
how do i call a c# method from c++ (instead of overriding the event handler. i'll call a c# method
in a different dll)
rather have something you don't need, than need something you don't have
|
|
|
|
|
ok i compiled the c++ with /clr now c# adds the reference
rather have something you don't need, than need something you don't have
|
|
|
|
|
got it working with dllimport but cannot get it to call a c++ method
c#code :
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Runtime.InteropServices;<br />
<br />
<br />
namespace ConsoleApplication2<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
int mine = tester();<br />
Console.WriteLine(mine);<br />
<br />
}<br />
<br />
[DllImport("touchlib.dll", EntryPoint = "tester",<br />
ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]<br />
static extern int tester();<br />
}<br />
<br />
<br />
}<br />
c++ code
<br />
int Touchable::tester()<br />
{<br />
return 5;<br />
}
rather have something you don't need, than need something you don't have
|
|
|
|
|
Hi,
DllImport is used to call native code such as Win32 functions.
if your C++ dll is .NET code, just call the C++ class as if it were C#.
|
|
|
|
|
should i add a using <dllname.dll> ?
and for functions in a class do i need to call Class::function()?
rather have something you don't need, than need something you don't have
|
|
|
|
|
donsolms wrote: should i add a using ?
yes
donsolms wrote: for functions in a class do i need to call Class::function()?
no
calling any CLR compliant language obeys the rules of the calling language, hence
in C# you need a using statement, and call as class.method(args) or object.method(args).
|
|
|
|
|
i can't get the using to work. i have the c++ dll in a namespace named touchlib and then a class named Touchable.
<br />
using touchlib;<br />
doesn't work, i have added a reference to the dll. a i missing something, maybe in the compiling of the dll? how can i be sure that the dll is managed c++? what type of vc++ project is managed c++?
rather have something you don't need, than need something you don't have
|
|
|
|
|
Hi,
I dont remember the details for C++, but you did build the C++ dll, didnt you ?
so you know it is/isnt managed code.
if you were able to add a reference to it in your C# app, it must be managed code.
now Intellisense should show the available classes (C# and managed C++).
|
|
|
|
|
thanks a lot, it is working 100% now.
i might have referenced an older version of the dll somehow, and after a simple clean solution for the c++ dll and c# project made it work.
thanks again
rather have something you don't need, than need something you don't have
|
|
|
|
|
Hi.
I want the algorithm for solving 3Evaluation-3Passive :
ax+by+cz=d
ex+fy+gz=h
kx+ly+mz=n
I can solve this in math, but I confused of using this way as an algorithm
Best wishes
|
|
|
|
|
So what makes you confused? At what stage? Also there is a special forum for math and algorithms
|
|
|
|
|
I'm not familiar with 3Evaluation or 3Passive. However if you can solve it in math it should not be too hard to solve it in C#. Your algorithms that use complex functions would use methods in the Math library within the framework. For example if part of the code required getting a cosine of the delta between x prime and x n, then you would write..
xPrime = someValue;
xN = newValue;
skewedResult = Math.COS(xPrime, xN);
The only thing you'd have a pain with is if you have to take a differential of an equation.
|
|
|
|
|
How can I build a windows form which contains a table?
|
|
|
|
|
What table????????
SG
|
|
|
|
|
There's a toolbox in the designer. You should be able to click and drag one of many kinds of tables from there.
|
|
|
|
|
I have an application where the user can enter a string to pass to the com port. A common string for this program is "W\r" with \r being carriage return.
When the program passes the string through the accessor, it shows up through the debugger as scaleStation.SendString = @"W\r". I don't want the literal value "W\r", I want "W" with a carriage return.
I ended up using the following for the solution, but was wondering if there is a better way to do this? I am worried the user may find another escape string that I may not have coded for.
string ss = scaleStation.SendString;
SendStr(ss.Replace(@"\r","\r"));
Thanks for your ideas!
Hogan
|
|
|
|
|
The debugger is indeed showing it right! It's just showing the string representation of carriage return. The @ is to make sure that the '\' is not taken as an escape sequence. In essence, the Replace you do does not accomplish anything.
SG
|
|
|
|
|
Maybe I didn't explain myself correctly, but the replace I put in the code did fix the problem.
I'll try again.
If I call the command SendStr("W\r"), it passes a Capital W and carriage Return to the com port. This works as desired as the device attached is expecting this string.
If I set a variable through a text box, I get the value @"W\r" passed literally to the device with no carriage return. So the command looks like SendStr(stringVariable).
Sample Application code: http://www.snorkie.com/codesamples/stringsample.txt
Set your breakpoint at line 105. Press the button and look at the value of the two variables s and s2 by putting your mouse over them or using the watch. You will see that they are different...
s = "W\r"
s2 = @"W\r"
Using the value from s2 won't pass the carriage return I need for my device. Converting s2 using the code s2.Replace(@"\r","\r") does give me the value I need.
So again, I have a solution, but I think there has to be a better one. Does anybody see a better way to do this?
Thanks
Hogan
|
|
|
|
|
There are 14 different escape codes[^].
You can use the RegEx.Replace method with a pattern like "\\([\\0bfnrtv])", and a delegate to determine the replacement character, to replace them.
---
single minded; short sighted; long gone;
|
|
|
|