Showing posts with label Programowanie ogólnie. Show all posts
Showing posts with label Programowanie ogólnie. Show all posts

Friday, November 12, 2010

Against a wall... C#

Today I have realized that my knowledge about C++ and C# is almost like nothing. That counts for JAVA most probably... I've been dealing with different assemblers, shell scripts, perl scripts, a lot of PL/SQL, soma JAVA. And I have worked with ANSI C, C++, C#. And many more.
What is wrong about my skills? I have tried to use DisassembleShader code from the DIrectX. I found that there is ShaderLoader but... no disassembler ?!?
I was able to call the method directly using ImportDll, but then I am not able to work with all the fancy things that are marshaling, reflections, interoperability, unmanaged code, etc.
What I have achieved (maybe someone would find it useful) is:

[DllImport("D3dx9_24.dll" , SetLastError = true)]
// This is probably wrong to use the specific DLL instead of ex. COM GUID
private static unsafe extern IntPtr D3DXDisassembleShader(
[In]void* pShader,
[In]bool EnableColorCode,
[In]string pComments,
[return: MarshalAs(UnmanagedType.Interface)]
[Out]void* ppDisassembly
);

Now the tricky parts.
This method returns HRESULT (where C# equivalent can be IntPtr). The returned value is D3D_OK if everything went OK. D3D_OK maps to S_OK which maps to 0. Thus the expected returned value is 0.
More important piece is the ppDisassembly. This is an UnmanagedType.Interface which is in fact ID3DXBuffer (http://msdn.microsoft.com/en-us/library/bb205753(v=VS.85).aspx). It inherits from IUnknown and adds its own methods there. This is something that I don't know how to access. I have searched over the internet and this knowledge is beyond my current limits.
I think that I should use P/Invoke here, define an interface, access it. But... my knowledge is currently not enough to do this... :(

Tuesday, December 30, 2008

Jak pisać dobre oprogramowanie?

Dziś troszkę o standardach i zasadach tworzenia dobrego oprogramowania. Zadziwiające jak niewielu ludzi je zna.
  1. Jeśli używasz daty - zawsze używaj formatu daty zgodnego z ISO-8601. Jeśli nie znasz normy to nie wiesz jak zapisywać daty. Norma podaje również powody dla których należy z niej korzystać. I jest międzynarodowa. Po prostu - przeczytaj, ucz się i nie popełniaj błędów które inni popełnili.
  2. Jeśli tworzysz programowanie w językach wysokiego poziomu - używaj wzorców projektowych. Nie wiesz czym one są? To jakby zasady gramatyczne. Możesz znać litery nie umiejąc pisać. Możesz nawet umieć pisać nie znając gramatyki/ortografii (i robić błędy). Możesz też używać wzorców programistycznych/projektowych.
  3. Myślisz że wiesz coś na pewno? Poczytaj standardy - zapewne zmienisz zdanie. Poczytaj standardy - warto.
  4. Jeśli coś robisz - staraj się to robić dobrze. Nie najlepiej jak jest to możliwe - ale najlepiej jak możesz w danej sytuacji.
  5. Myślisz że coś robisz dobrze... więc sprawdź czy ktoś nie robił tego tak samo przed tobą. I nie popełnił tych samych błędów, które właśnie zamierzasz popełnić.
  6. Nie traktuj tych porad jako wiedzy absolutnej - ja się ciągle uczę nowych rzeczy.