|
All managed code written from a language which targets the CLR compiles to Intermediate Languages, or IL. Assemblies are language-independent. Just add a reference to this managed assembly in your C# project, just like you reference System.* assemblies (almost all written in C#) in VB.NET. As far as assemblies are concerned, the source language in which they were written does not matter (although some languages support more features of Microsoft IL (MSIL) than others).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the help!
Happy Programming!
WWW::CodeProject::BNEACETP
|
|
|
|
|
In your opinion, what's the best language to develop .NET applications ??
Free your mind...
|
|
|
|
|
IMO, C#. It was, after all, written from the ground-up for the .NET Framework and supports almost every feature of MSIL based on what I've read in the ECMA standard for the Common Language Infrastructure (CLI). It also offers a syntax similar to many powerful languages like C++, Java, and Perl which makes learning and knowing other languages easier.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks.
Free your mind...
|
|
|
|
|
All is in the title:
I want to store and return references to objects.
How can I do that?
Thanks
|
|
|
|
|
Foo(ref object oMyObj)
Bar MyBar = new Bar();
Foo(ref MyBar)
|
|
|
|
|
Why are you ref'ing an object? It's already a reference type. This is really only necessary for value types.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Typing to fast and doing to many things at once
Haste makes waste I guess
|
|
|
|
|
Because it's not the same kind of reference...? A ref parameter behaves like a reference in C++ - you can modify what it refers to.
static void Foo(ref string str) {
str = "Yo";
}
static void Main(string[] args)
{
string s = null;
Foo(ref s);
Console.WriteLine(s);
}
--
<british-accent>Pass the jam, would you?
|
|
|
|
|
Yeah but I misread the original question. He wanted to store and retrieve not pass the object to a method.
|
|
|
|
|
Yeah I saw that later in Heath's response. Anyhow, Heath was generalizing a bit too much on references. They are handy at times just as out .
--
<british-accent>Pass the jam, would you?
|
|
|
|
|
For strings, yes, because they are immutable and handled a little differently. I agree that ref and out are handy even in managed code (they are often necessary when P/Invoking native methods, sometimes even with reference types (like for pointer pointers)), but in the case discussed here they are not.
Keep in mind, though, that objects do not require this - only value types and strings (guess I should'be mentioned that too, but at the time I didn't think about it). Take this little example:
using System;
public class Test
{
public static void Main()
{
string s = string.Empty;
Console.WriteLine(s);
Foo(s);
Console.WriteLine(s);
Test t = new Test();
Console.WriteLine(t.s);
Foo(t);
Console.WriteLine(t.s);
}
private static void Foo(string s)
{
s = "Testing";
}
private static void Foo(Test t)
{
t.s = "Testing";
}
public string s;
public Test()
{
s = "This is a test";
}
} The output would be:
This is a test
Testing
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I see what you mean. Basically you're just creating a handle (the "reference"), in this case Test. Bear in mind that I do COM on a daily basis. [out] is God.
--
Try walking in my shoes. You stumble in my footsteps.
|
|
|
|
|
Properties and fields, a basic element of objects:
public class MyClass
{
private object o1;
private object o2;
public MyClass()
{
}
public object O1
{
get { return this.o1; }
set { this.o1 = value; }
}
public object O2
{
get { return this.o2; }
set { this.o2 = value; }
}
} Can you use fields instead if they are public, but properties are recommended because you can check the value before assigning them to your private fields ("store").
You should read the topics discussed in the .NET Framework SDK as well as vast collection of articles here on CodeProject for examples.
If you're talking about serialization, see http://msdn.microsoft.com/library/en-us/cpguide/html/cpovrserializingobjects.asp[^]. This gives an overview of serialiation as well as advanced topics and many examples using binary and SOAP serialization, as well as the more basic XML Serialization (which doesn't handle everything that true serialization, but is good to use in many cases such as storing configuration options and application state. There are several articles here on CodeProject that discuss those. Just do a search for serialiation.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I am trying to develop a program for the PocketPC in C#. It requires the use of cdmapi which only is available in the SDK as cemapi.h and cemapi.lib for C++. I really don't want to do this in C++.
How can I use/access/import/convert/??? the available library for use in C#.
Thank in advance for the advice
camasmartin
hobby programmer
|
|
|
|
|
You'll have to P/Invoke all the functions and redefine the structs and interfaces, as well as the constants/enumerations required for the functions and interface methods.
I'm not on my machine with the WinCE SDK, but since the CEMAPI exposes COM interface, it might also use a typelib. In this case, you can use tlbimp.exe to import a typelib as a COM interop assembly (RCW).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
This is what I would like to do:
1. Read in a WAV file
2. Break it up into segments of 256 samples each, with an overlap of 64 samples.
3. Refer to each segment as Segment[i] where "i" is the number of samples.
I'm done with steps 1 and 2. This is the code block that I used to segment the samples:
// *** CODE FOLLOWS ***
// For the WAV file I'm working with, there are 17 such segments
for(int i = 0; i < 17; i++)
{
for(int j = 0; j < 256; j++) {
WaveSegment[i,j] = objWaveToSegment.Data[(i*64) + j];
}
}
/// *** END OF CODE ***
In the above snippet, objWaveToSegment is an object of another class that reads in the WAV file and provides access to it's data.
Now, how do I create 17 1*256 arrays called "Segment" such that when I refer to Segment[1] I get samples 0..255, Segment[2] is 64..319 etc.
Thank you for your replies in advance 
|
|
|
|
|
Probably a too simple answer but I suppose this would do the job
public WaveSegment[] GetWaveSegment(int index){
WaveSegment[] ws=new WaveSegment[256];
for (int arrIdx=0;arrIdx,256;arrIdx++0{
ws[arrIdx]=WaveSegment[index,arrIdx];
}
return ws;
}
Maybe you could also investigate the Array.Copy static method
|
|
|
|
|
In this example, is WaveSegment[] a separate class that I perform the segmentation in? Or is it a function?
I apologize for my ignorance, but I'm really new to all this.
|
|
|
|
|
Why not just use a jagged array, a.k.a. an array of arrays? When you get Segment[0] (note, all .NET languages use 0-based indexes, not 1-based indexes!) you get an array of 256 elements, whatever they are:
WaveSegment[] segments = new WaveSegment[17];
for (int i=0; i<segments.Length; i++)
segments[i] = new WaveSegment[256]; You can then access them in several ways, including:
WaveSegment[] innerSegments = segments[0];
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath, thanks again for your help.
Sorry for the index gaffe. I was aware of that, but was obviously not paying attention while typing.
Could you please explain the following code:
WaveSegment[] segments = new WaveSegment[17]; and
WaveSegment[] innerSegments = segments[0];
What is WaveSegment[] here? A class, a function or a jagged array?
I'm new to all this, and apologize for the dumb questions.
|
|
|
|
|
I don't know - you used it in your code fragment so I thought I'd reuse it. Maybe I'm using wrong in your context, but the idea is the same. WaveSegment could be anything: a class, struct, enum, or even a delegate! All you're doing is making an array of an array of something (no, I didn't stutter! ). The first line made an array of WaveSegment with 17 elements. In my code fragment, I then created a new array of 256 elements within each of those 17 elements. The second line above merely gets that 256-element array from the first array element from the array with 17 elements.
See Arrays[^] in the C# Language Features reference on MSDN, or more specifically Jagged Arrays[^] for more information.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath, thanks for your detailed replies!
Ok, here's what I've done, incorporating your suggestions and that of my anonymous helper.
public class Segmentation
{
private static void Main()
{
Random R = new Random();
int[] inArray = new int[1280];
for(int i = 0; i < 1280; i++)
inArray[i] = i;
int[][] arrSegmentArray = new int[17][];
for(int i = 0; i < 17; i++)
{
arrSegmentArray[i] = new int[256];
Array.Copy(inArray, 64*i, arrSegmentArray[i], 0, 256);
Console.WriteLine(arrSegmentArray[i].ToString());
Console.ReadLine();
}
}
}
However, where I expect arrSegmentArray[i] to be printed as a 256 element array, all I see is System.Int32[];
What do I need to fix here?
|
|
|
|
|
Heath, thanks for your detailed replies!
Ok, here's what I've done, incorporating your suggestions and that of my anonymous helper.
public class Segmentation
{
private static void Main()
{
Random R = new Random();
int[] inArray = new int[1280];
for(int i = 0; i < 1280; i++)
inArray[i] = i;
int[][] arrSegmentArray = new int[17][];
for(int i = 0; i < 17; i++)
{
arrSegmentArray[i] = new int[256];
Array.Copy(inArray, 64*i, arrSegmentArray[i], 0, 256);
Console.WriteLine(arrSegmentArray[i].ToString());
Console.ReadLine();
}
}
}
However, where I expect arrSegmentArray[i] to be printed as a 256 element array, all I see is System.Int32[];
What do I need to fix here? 
|
|
|
|