|
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? 
|
|
|
|
|
Glad you solved it, but just for future benefit, the line Console.WriteLine(arrSegmentArray[i].ToString()); is calling ToString on a Int32[] array. The default implementation of Array.ToString() (inherited from Object.ToString ) is to simply print the namespace-qualified class name.
-----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-----
|
|
|
|
|
What I did was this:
for (int i =0; i < 17; i++)
{
for (int j=0; j < 256; j++)
{
Console.Write(arrSegmentArray[i][j].ToString()+" ");
}
Console.WriteLine(); Console.ReadLine();
}
Is that alright?
|
|
|
|
|
Sure, why not?! It just depends on your requirements and implementation.
-----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-----
|
|
|
|
|
Solved it. Thanks for your help!
|
|
|
|
|
Is it possible to customize the open dialog box to show a preview of the selected file?
|
|
|
|
|
If the OS supports it, a user can switch to the Thumbnail view. Other than that, the two derivatives of FileDialog (OpenFileDialog and SaveFileDialog ) cannot easily be modified. In fact, this is a major problem that many people have faced. These two dialog classes encapsulate the OPENFILENAME struct and the GetOpenFileName and SaveOpenFileName Win32 functions. In order to customize dialogs using the struct, you have to provide a Dialog resource - a Win32 resource, not a .NET resource. This can be very difficult even with native applications.
The typical solution is to make your own form and use various controls for the tree and list views. Another option is to make a mixed mode Managed C++ class that can use dialog resources and encapsulate all this in a .NET class that you can use from a different .NET language like C#.
-----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-----
|
|
|
|