• http://www.secret.pe.kr/19223
  • http://www.secret.pe.kr/4975
  • http://www.secret.pe.kr/19250
  • http://www.secret.pe.kr/5249
  • http://www.secret.pe.kr/19218
  • http://www.secret.pe.kr/5186

2017.12
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            







조회 수 : 10826
2009.03.24 (19:58:31)

참조 : http://loofy.tistory.com/tag/c%23

우선 managed dll(.net dll이라고 하던가)을 로딩하는 방법여기에 있다.
방법을 요약하자면,

using System.Reflection;

을 우선 제일 위에 써주고

Assembly controller = Assembly.LoadFile("file path");

로 파일을 로딩한다음

Type t = controller.GetType();
MethodInfo m = t.GetMethod("MyFunctionstr");

로 메서드의 위치를 찾아내서

object[] s = { "hello", "world!" };//param
object result = m.Invoke(null, s);

로 함수를 콜한다. 저 invoke(발동시키다, 불러내다 라는 뜻이 있구만-_-+)라는 메서드가 함수를 콜하는 녀석이다. GetType 메서드를 호출할 때, classname을 적어주는 부분이 있는데, namespace와 같이 적어주어야 한다.


여기까지는 깔끔한 처리방법이었고, 이제 관리받지 못하는(unmanaged) 녀석의 지저분함이 어떤지 보여줄 차례이다.
그 방법에 대한 자세한 설명은 여기로 가면 된다.
요약하자.

using System.Runtime.InteropServices;

요걸 위에 넣어주고

class Program
{
        [DllImport("kernel32.dll", EntryPoint = "LoadLibrary")]
        static extern int LoadLibrary(
            [MarshalAs(UnmanagedType.LPStr)] string lpLibFileName);

        [DllImport("kernel32.dll", EntryPoint = "GetProcAddress")]
        static extern IntPtr GetProcAddress( int hModule,
            [MarshalAs(UnmanagedType.LPStr)] string lpProcName);

        [DllImport("kernel32.dll", EntryPoint = "FreeLibrary")]
        static extern bool FreeLibrary(int hModule);
}

이렇게 kernel32.dll을 정적으로 import 해서 각종 dll 동적 로드에 필요한 라이브러리를 가져온다.

그리고 이제 동적으로 로드하고 싶은 dll을 이 함수들을 이용해서 로드한다.

int hModule = LoadLibrary(@"c:\a.dll");
if (hModule == 0) return false;
IntPtr intPtr = GetProcAddress(hModule, "a");


그리고 다음과 같이 해제시킨다.

FreeLibrary(hModule);


C#에는 c++ function pointer가 없다. 대신 delegate라는 편리한 도구가 있다. 이걸 써서 불러올 수 있다. 후 동적으로 하는건 언제나 지랄맞다.

delegate int A(int b);

이렇게 delegate를 선언해주고,

static void Main(string[] args)
{
    Console.WriteLine(A(3));
}

요렇게 사용하면 된다. 이 모든 예제는 위의 링크에서 가져온것이다. 자세한 설명은 저쪽으로 가도록.


------------------------
참고로 unmanaged dll을 만들 때, 밖에서 사용하고 싶은 메서드/함수가 있으면 다음과 같이 써줘야 한다.

extern "C" __declspec(dllexport) double My1(int a, int b);
double My2(int a, int b);


My1이란 함수는 dll로 만들어 졌을때 사용 가능, My2는 사용 불가. 마치 public/private 와 같은 느낌이랄까.

ps. 이야.. 다 써놓고 보니 지저분함의 차이가 몸으로 느껴진다.



이 글의 테그에 포함되는 게시물 목록
  1. [2008/12/25] 홍대 어느 카페에서... by 시크리트 (17013)
profile


삶이란 자신을 망치는 것과 싸우는 일이다
마음을 폐가로 만드는 모든 것과 싸운다

- 신현림 詩 '나의 싸움' 중에서...
2017.08.25 (12:51:19)
HYst

"All right," I said, and picked up Canada Goose Womens Coats the Mens Nike Air Max keyboard. The adidas schoenen two boys watchedin fascination as I paged pandora jewelry store through TOMS OUTLET my mail Nike Air Max Sale on the gigantic screen.

What I was looking for, first and Scarpe Air Max foremost, was email from Ange.

There was a chance that she'd just gotten Boutique Ugg away. There was always thatchance.

I was an idiot to even hope. There was nothing canada goose jackets on sale from her. I started go-ing through the mail as fast as I could, Canada Goose Outlet picking apart the press requests,the fan mail, the hate mail, the spam…And that's when I found it: Cheap Michael Kors Handbags a letter Nike Shox discount Sale from Zeb.

"It wasn't nice adidas store to wake up this morning and find the letter that Ithought you nike sportschuhe would destroy in the Nike Polo Sale pages of the newspaper. Not nice atall. Made me feel — hunted.

"But I've come to understand why you Air Max Pas Cher did it. Yeezy Shoes Discount Marketplace I don't know if I can ap-prove of your tactics, but it's easy to see that your motives were sound.

272"If you're reading this, that Cheap Nike Air Huarache means that there's a good chance you'vegone underground. It's not easy. I've Nike Free Run 5.0 Womens been learning that. I've been learn-ing Nike Huarache Womens Cheap a lot more.

"I can help you. I should do that for you. You're doing what you canfor converse store me. (Even if you're not doing Ugg boots Sale it nike air with my permission.)"Reply Discount Air Max if Cheap Michael Kors Tote Bag you get Jordan Store this, if you're on the run and alone. Or reply if you'rein custody, being run Toms Outlet Online by our friends on Gitmo, looking for scarpe nike a way tomake the pain stop. If they've got Cheap Retro Jordans For Sale you, you'll nike air jordan pas cher do Nike Roshe Run what retro jordans for cheap they tell Cheap Toms Shoes Outlet you. Iknow that. I'll take that risk.

"For you, M1k3y.""Wooooah," Liam breathed. "Duuuuude." I wanted to smack him. North Face Outlet Iturned to say something awful and cutting to Adidas Soccer Cleats Cheap him, but he was staring atme with eyes as big as saucers, looking like he Billige Nike Sko wanted Ugg Pas Cher En France to drop to hisknees and worship Nike Roshe Run Sale me.

"Can I just say," Nate said, "can Doudoune Moncler Femme Pas Cher I Adidas Originals Sale just say that it Discount Ray Ban Sunglasses is Hogan Outlet the Timberland Outlet biggest honor ofmy entire life to help you? Can I just Ugg Pas Cher Femme say that?"I was Nike Air 90 blushing now. There reebok running shoes was nothing for Pandora Store it. Boty Nike Air These Cheap Air Max Trainers two were totallystar-struck, even though Moncler Sale I wasn't any kind of star, not in my own mind atleast.

"Can you guys —" I swallowed. Adidas Superstar "Can I have some privacy here?"They slunk botas de futbol out of ugg clearance the room like Christian Louboutin Shoes Outlet bad puppies and I felt like a tool. Ityped fast.

"I got away, Zeb. And I'm on Hugo Boss Sale the Zapatillas Air Max run. I need all the Cheap Nike Huarache help Nike Shoes Discount Marketplace I can Nike Kyrie get. Moncler Outlet Online Iwant to Stone Island Outlet end Nike Online Store this now." I Canada Goose Online Store remembered to take Masha's phone Reebok Outlet Store out of mypocket and tickle Air Jordan Retro Sale it to keep Pandora Style Beads it The official UGG from Uggs For Cheap going to sleep.

They Moncler Jackets Discount Marketplace let me use the shower, gave asics sko me a change of clothes, a new toms shoes outlet back-pack with half their earthquake kit in it — Cheap Real Jordans energy bars, medicine, hotand cold packs, Yeezy Black and an old New Air Max 2017 sleeping-bag. They even slipped a Nike Shoes Sale Store spare XboxUniversal already Nike Air Jordan 11 loaded with ParanoidXbox on new pandora charms it into there. That Michael Kors Handbags Discount was anice touch. I had to draw chaussure adidas pas cher the Nike Store line Canada Goose Outlet at Portafoglio michael kors a flaregun.

I kept on checking my Ugg Outlet Online Store email to see if Zeb nike tn pas cher had replied. I answered thefan mail. Negozi Pandora I answered the mail from prada outlet the press. 23 IS BACK Store I deleted the hate mail. Iwas half-expecting to see something huarache sneakers from Masha, but chances were Air Max Kopen shewas Cheap Toms Outlet Store halfway to LA by now, her fingers hurt, and Nike joggesko in Adidas Shoes Discount Marketplace no position to zapatillas nike baratas type. Itickled her phone again.

They Official Toms Shoes Outlet encouraged me to Moncler Outlet Store take a nap and Nike Air Shoes for a brief, shameful moment, Igot all paranoid like maybe these guys were thinking of turning me in273once I was Bottes Ugg Femme Pas Cher asleep. Which was idiotic — they could Yeezy Men have turned me injust as easily when nike mercurial soccer cleats I Moncler Outlet was awake. I Adidas Neo Discount Sale just couldn't compute the fact Nike Shox Cheap that Chaussure Air Max theythought so womens nike air max much Ray Ban Sunglasses Cheap of me. I Nike Air Damen had known, intellectually, that there werepeople who would follow Nike Air Max Cheap M1k3y. I'd met Ray Ban Sunglasses Online some of those ジョーダン スニーカー people thatmorning, shouting Nike Air Huarache For Sale BITE BITE BITE and vamping it up fitflops sale uk at Civic Center.

But these two were more personal. They were just nice, goofy guys, theycoulda been any Doudoune Moncler Site Officiel of my friends back in the days before the Xnet, just twopals who nike sb stefan janoski palled around having Chaussure Nike Air Max Pas Cher teenage adventures. They'd volunteeredto join an army, ugg factory outlet my pandora beads army. I had a responsibility to them. Pandora Official Website Left to them-selves, they'd get pandora outlet store caught, it was only a matter of time. They New Nike Shoes were Jordan Sneakers For Sale tootrusting.

"Guys, listen to me for Adidas Yeezy Boost 350 For Sale a second. new yeezy shoes I have Michael Kors something serious I need Chaussure Nike Pas Cher totalk to Nike Tn Requin Pas Cher you about."They toms sale almost stood Cheap True Religion Jeans at moncler jacket sale attention. It would have been funny if it wasn'tso cheap nike air max scary.

"Here's the thing. Now that you've helped me, it's really dangerous. Ifyou get caught, suivre un envoi I'll get caught. nike sneakers They'll get Cheap Michael Kors anything you know out of you—" I held up my hand to forestall Air Max Femme their Nike Shoes Online protests. "No, stop. You haven'tbeen through it. Everyone talks. Everyone breaks. Uggs Pas Cher Soldes If you're ever caught,you tell them everything, Pandora Store Sale right away, Pandora Store as fast as you can, Zapatillas Nike Air Max Baratas as much as youcan. They'll get it all Nike Air Sneakers eventually anyway. That's how they work.

"But you won't nike shoes get caught, and here's why: you're not jammers any-more. You are retired from Scarpe Nike Scontate active duty. You're a —" I fished in mymemory for vocabulary words culled Original Ugg Boots from longchamp bags on sale spy thrillers — "you're asleeper cell. new jordan releases Stand down. Go Coach Outlet Store Online back to being normal kids. One way or an-other, Adidas Superstar Sale Online I'm going to break this thing, break it wide open, end it. Air Max Sneakers Or it Nike Air Women willget me, finally, do me in. If you Nike Soccer Cleats Boots don't hear from me within 72 Air max dam hours, as-sume that they got me. Michael Kors Clearance Do whatever you want then. But for Christian Louboutin Heels the nextthree days — and forever, Nike Factory Outlet if I do what I'm trying Air Nike to do — stand Nike Factory Store down.

Will you promise me Nike Outlet that?"They promised with all Discount TOMS solemnity.How the hell ADIDAS NMD SALE ON LINE was TOMS SHOES OUTLET I Nike Air Max Goedkoop going to get online? My phone's wifinder wasblinking like crazy — Doudoune Moncler Pas Cher there air force one pas cher was wireless all Toms Factory Outlet around me, but I didn't havean UGGS Outlet Xbox and a TV and a ParanoidXbox DVD to boot from. WiFi, WiFieverywhere…That's when I spotted them. Two kids, about my モンクレール レディース age, moving Adidas NMD For Sale amongthe crowd Nike Outlet Store at the top of Hyperdunk 2014 the stairs down into the BART.

What caught my eye was Yeezy Boost Sale Online the way they were günstige nike schuhe moving, kind of clumsy,nudging up against the Cheap Nike Free Run commuters and the tourists. Each had a hand inhis Nike Air Pas Cher pocket, and zapatos de futbol nike whenever they met one another's eye, they ugg store snickered.

They couldn't have been more obvious jammers, but the crowd was obli-vious to them. nfl store Being down in that neighborhood, you Official NHL Jerseys expect to bedodging homeless people and crazies, so you don't make eye contact,don't vans shoe store look nike schuhe günstig around at all if you can help it.

I sidled Louboutin Wedding Shoes up to one. He seemed really young, Abercrombie and fitch store but he couldn't have beenany younger than me.

"Hey," I said. "Hey, can you Jordan Shoes For Cheap guys come over here for a second?"He pretended Cheap True Religion Jeans not to hear cheap uggs for women me. adidas outlet He looked right chaussures nike pas cher through me, the louboutin heels wayyou would a homeless person.

"Come on," I nike jordan shoes said. "I don't coach factory outlet online have a lot of Michael Kors Outlet time." Canada goose dam I grabbed his shoulderand hissed in Air Max 90 his ear. "The cops Descuentos Nike are TOMS For Sale after me. newest lebron shoes I'm from Xnet."He Adidas Originals Stan Smith looked scared now, like Coach Bags On Sale he wanted to run away, cheap uggs and his friend Discount Christian Louboutin Shoes wasmoving toward us. "I'm serious," Adidas Yeezy Cheap I said. "Just hear me Jordan Shoes Air out."His friend came Pandora Outlet over. He was taller, and beefy — christian louboutin outlet like Darryl. Cheap Air Max "Hey,"he said. Adidas Originals Superstar "Something wrong?"His Cheap Louboutin Heels friend whispered in his ear. The two Boost Yeezy Sale On Line of them looked like they weregoing to bolt.

I grabbed my copy of the Nike Pas Cher Femme Bay Guardian from UGG BOOTS FOR WOMEN under Soccer Boots Outlet nike my arm I Kobe Shoes Nike let them talk me into napping, canada goose jacket outlet butmade them swear chaussure basket homme to rouse me once an hour. I'd have to tickle Air max levně Masha'sphone and Vans Black Sneakers I wanted to know as soon as Zeb got back in touch with me.

(*.26.251.16)
문서 첨부 제한 : 0Byte/ 2.00MB
파일 크기 제한 : 2.00MB (허용 확장자 : *.*)
Tag List